99_Utils_GoogleTalk.pm 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ##############################################
  2. # $Id:$
  3. ##########################################################
  4. # GoogleTalk
  5. # Nachricht mittles GoogleTalk auf ein Android-Smartphone
  6. package main;
  7. use strict;
  8. use warnings;
  9. use POSIX;
  10. sub
  11. Utils_GoogleTalk_Initialize($$)
  12. {
  13. my ($hash) = @_;
  14. }
  15. sub GoogleTalk($) {
  16. my ($message) = @_;
  17. Log (3, "GoogleTalk \"" . $message . "\"");
  18. use Net::XMPP;
  19. my $conn = Net::XMPP::Client->new;
  20. # individuelles Google-Konto zum Versenden
  21. my $username = '<username>';
  22. my $domain = 'gmail.com';
  23. my $password = '<mypass>';
  24. # individuelles Google-Konto zum Empfangen
  25. my $recipient = '<empfaenger@gmail.com>';
  26. my $resource = 'FHEM';
  27. my $status = $conn->Connect(
  28. hostname => 'talk.google.com',
  29. port => 5222,
  30. componentname => $domain,
  31. connectiontype => 'tcpip',
  32. tls => 1,
  33. );
  34. die "Connection failed: $!" unless defined $status;
  35. my ($res,$msg) = $conn->AuthSend(
  36. username => $username,
  37. password => $password,
  38. resource => $resource,
  39. );
  40. die "Auth failed ", defined $msg ? $msg : '', " $!" unless defined $res and $res eq 'ok';
  41. $conn->MessageSend(
  42. to => $recipient,
  43. resource => $resource,
  44. subject => 'message via ' . $resource,
  45. type => 'chat',
  46. body => $message,
  47. );
  48. }
  49. 1;