Skip to content

Instantly share code, notes, and snippets.

@onlurking
Created July 17, 2015 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onlurking/648a775f2f9765107f66 to your computer and use it in GitHub Desktop.
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.
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 = 'user@chat.facebook.com'
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)
@ryukinix
Copy link

ryukinix commented Aug 3, 2015

Satan-code.

@onlurking
Copy link
Author

@ryukinix, agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment