PHP Chat Bot: Google Talk

扶醉桌前 提交于 2020-01-12 02:31:40

问题


I was wondering how to create a chat bot for Google Talk via special client.

I know it uses XMPP to send messages, but I do not know how to use this at all. It is my understanding that I should be able to make a bot which chats for me when I am away if I were to create my own client page, which would parse the chats with my data. Where would I begin if I wanted to create a custom client, and how could I make it parse messages and autorespond in a set manner? My intended usage: autoresponder for when I am AFK, with a decent AI (which I can make.)

Can I use this protocol with PHP to make my bot, or must it be java or python based?

Thanks for any and all help!!!


回答1:


The xmpphp library should help you. Have a look at the examples.

PHP is absolutely the last language I would use for something like this (well, okay, I wouldn't do it in awk or sed either), but if you're set on using it, you can.




回答2:


Give a look to this library:

  • xmpphp

Gives you a fully OOP API (> PHP5) to communicate using this protocol.

By default it uses TLS so you will not have any problems connecting to the talk google server.

Check this code example:

<?php
include("xmpp.php");
$conn = new XMPP('talk.google.com', 5222, 'username', 'password', 'xmpphp',
                 'gmail.com', $printlog=False, $loglevel=LOGGING_INFO);
$conn->connect();
$conn->processUntil('session_start');
$conn->message('someguy@someserver.net', 'This is a test message!');
$conn->disconnect();
?>


来源:https://stackoverflow.com/questions/1220340/php-chat-bot-google-talk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!