Created
July 17, 2015 12:31
-
-
Save onlurking/648a775f2f9765107f66 to your computer and use it in GitHub Desktop.
Cleverbot <-> Facebook Chat, dependencies are sleekxmpp and https://github.com/pierredavidbelanger/chatter-bot-api/, but sadly Facebook deprecated the Chat API, the code doesn't work as expected.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sleekxmpp | |
import logging | |
from chatterbotapi import ChatterBotFactory, ChatterBotType | |
factory = ChatterBotFactory() | |
bot1 = factory.create(ChatterBotType.CLEVERBOT) | |
bot1session = bot1.create_session() | |
logging.basicConfig(level=logging.DEBUG) | |
def session_start(event): | |
chatbot.send_presence() | |
print('Session started') | |
chatbot.get_roster() | |
def message(self, msg): | |
if msg['type'] in ('normal', 'chat'): | |
print('msg received') | |
s = msg['body'] | |
print('victim: ', s) | |
rep = bot1session.think(s) | |
rep.replace('Cleverbot', '') | |
print('bot: ', rep) | |
msg.reply(rep % msg['body']).send() | |
jid = '[email protected]' | |
password = 'password' | |
server = ('chat.facebook.com', 5222) | |
chatbot = sleekxmpp.ClientXMPP(jid, password) | |
chatbot.add_event_handler('session_start', session_start) | |
chatbot.add_event_handler('message', message) | |
chatbot.auto_reconnect = True | |
chatbot.connect(server) | |
chatbot.process(block=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ryukinix, agreed.