fbchat icon indicating copy to clipboard operation
fbchat copied to clipboard

Send a message based on the title of the marketplace post

Open effeci opened this issue 5 years ago • 1 comments

import fbchat
from fbchat.models import *


class EchoBot(fbchat.Client):
    def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs):
     print("{} from {}".format(message_object, thread_id))
        if message_object.text == "POST TITLE":
       self.send(Message(text="hello...."), thread_id=thread_id, thread_type=thread_type)
    
bot = EchoBot(“user”, “pass”)
bot.listen()

So basically this is echobot example. The problem is that when someone texts me in for a marketplace post, I have to give a different answer based on the product From the listening in the terminal I see this type of chat as a group and asap the chat is opened the thread title gets changed to the name of the product. Now, where is this name stored? How can I parse if it's the text i'm looking for to give a certain answer? Thanks for the help.

effeci avatar Apr 26 '20 19:04 effeci

You can get the name of the thread using fetchThreadInfo

thr = client.fetchThreadInfo(thread_id)[thread_id]
name = thr.name # get the name of the thread where the message come from
if name == "product" # check if the thread name match the product name
    self.send(Message(text="answer"), thread_id=thread_id, thread_type=thread_type) # Reply when thread name match the product

trangcongloc avatar May 01 '20 13:05 trangcongloc