Exemple #1
0
# -*- coding: utf-8 -*-
from chatbot import ChatBot


def text_handler(bot, msg):
    uid = msg['FromUserName']
    text = str(msg['Content'])
    answer = bot.answer(uid, text)
    return answer.replace("<br />", "\n")

if __name__ == "__main__":
    chatbot = ChatBot("elastic")
    # comment below to avoid reloading FQA and other data, o.w. you should wait for a while before using the bot.
    chatbot.reload()
    service = chatbot.service("wechatmp").set_text_handler(text_handler)
    try:
        service.start()
    except KeyboardInterrupt:
        service.stop()
Exemple #2
0
if __name__ == '__main__':
    name = input("Enter profile name: ")
    print("Initializing...")

    # Extract account information from accounts.json file
    profile = Info(name)

    # Initialize Chat bot object
    bot = ChatBot(name)

    # Log in and connect to each account
    print("Logging In...")
    facebook_chat = FB(profile.email, profile.password, profile.contacts)
    print("All contacts connected...")

    # Ensure that the chats are closed when
    atexit.register(facebook_chat.close)

    while True:
        try:
            contact = facebook_chat.incoming_contact()
            print("Message from: ", contact.name)
            contact.send(bot.respond(contact.last_incoming()))
        except AttributeError:
            # Catch when there are no incoming messages from contacts
            pass
        else:
            while contact.incoming():
                continue
            bot.reload()