FB聊天自动回复消息功能仅在脱机时工作



我在python中使用过fbchat模块,它运行良好。当客户端正在侦听时,它会自动复制。但我希望它只在客户端脱机时自动复制。

def onMessage(self, author_id=None, message_object=None, thread_id=None, thread_type=ThreadType.USER, **kwargs):

toggle = client.fetchThreadMessages(thread_id=client.uid, limit=1) # client.uid means its our own acc
for message in toggle:
pText=message.text.lower()
log.info("toggle {}".format(toggle))

if("online" in pText):
self.markAsRead(author_id)
log.info("Message {} from {} in {}".format(message_object, thread_id, thread_type))  
msgText = message_object.text.lower()
if(msgText=="hi" or msgText=="hii" or msgText=="hiii" or msgText=="yo" or msgText=="hi there" or msgText=="hey" or msgText=="heyy"):
reply = "Hello :D"
elif(msgText=="hello" or msgText=="hellow" or msgText=="heloo" or msgText=="hlo" or msgText=="hellow"):
reply = "Hi :)"
elif(msgText=="hy" or msgText=="hyy"):
reply = "Hello :D"
elif(msgText=="whatsup" or msgText=="wassup" or msgText=="what's up" or msgText=="wtsup" or msgText=="watsup" or msgText=="whats up" or "how are you" in msgText or "hw r u" in msgText):
reply = "Awesome. What about you? :D"
elif(msgText=="test" or msgText=="debug" or msgText=="aboutme" or msgText=="about" or msgText=="bot"):
reply = "Hi, I'm a bot written in Python. Created by Nitish Ghimire"
elif("birthday" in msgText or "bday" in msgText or "hbd" in msgText):
reply = "Thank you! :D"
elif("what you doing" in msgText):
reply = "Idling, I'm a bot afterall. I work for my creator, Nitish Ghimire"
elif("bye" in msgText or msgText=="byye" or msgText=="byee"):
reply = "Ok bye! :D"
elif("who is your girlfriend?" in msgText or msgText=="girlfriend" or msgText=="byee"):
reply = "Shreejana GC <3"
else:
reply = "Thank you for contacting me. I'm currently not online, I was replying using a Python Script Created by Nitish Ghimire. I will reach out to you shortly."
def sendMsgg():
if (author_id!=self.uid):
self.send(Message(text=reply), thread_id=thread_id, thread_type=thread_type)
self.markAsDelivered(author_id, thread_id) 
if("online" in pText):
sendMsgg()

正如我过去研究这个主题一样,没有简单的方法可以了解某人的在线状态,甚至是你自己。相反,你可以有一个变通办法,比如为你的聊天机器人切换。

最新更新