1

我正在使用 fbmq 为 python 上的 Messenger 制作一个简单的机器人,可以处理快速问题。

当用户在我的工作时间之外向我的 Facebook 页面发短信时,我让机器人发送消息。

working_hours = [12,13,14,15,16]

if messaging_event.get('message') and (now.hour no in working_hours):
   page.send(sender_id, "Sorry we are closed!"

由于人们通常在不止一条消息中表达他们想要的东西,因此他们的聊天中充斥着“我们已关闭消息!”

我不太喜欢那个,因为我想给用户一个机会留言,以便我明天回答。

你知道我可以用什么方法让机器人发送“我们关门了!” 用户每发送 5 条消息?

我试过这个:

count = 0
if (count / 3 == 1):
  page.send(sender_id, "Sorry we are closed!")
  count = 0
if messaging_event.get('message') and (now.hour no in working_hours):
  count += 1

但它没有用。如果您有任何想法,我怎么能意识到我会非常感激:)

// 我尝试了一个while循环。

for messaging_event in messaging:

        sender_id = messaging_event['sender']['id']
        recipient_id = messaging_event['recipient']['id']

        messaging_event.get('postback'):
        messaging_event.get('message'):

        while (now.hour not in working_hours):
            count = 0
            if (count/3 == 1):
                page.send(sender_id, "Hello")

            if messaging_event.get('message'):
                count += 1

但它没有用。Facebook 向机器人发送消息时收到错误消息。

4

1 回答 1

0

好吧,我没有找到更好的解决方案。

count = 0
working_hours = [ 8... ]

@app.route('/', methods=['POST'])
def webhook():
    print(request.data)
    data = request.get_json()

    if data['object'] == "page":
        entries = data['entry']

        for entry in entries:
            messaging = entry['messaging']

            for messaging_event in messaging:

                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if now.hour not in working_hours:
                    global count
                if (count == 3):
                    page.send(sender_id, "We are closed!")
                if (count == 4):
                    count = 0
                if messaging_event['message'].get('text'):
                    count += 1

我现在想用时间戳来制作它,但老实说不知道怎么做。因此,例如,如果有一个用户你很长时间没有发短信,你会收到一条“欢迎回来,我们想念你”的消息。

我不确定这段代码如何与同时发短信的人一起工作。可能都是错误的,因为我使用了一个全局变量。如果您有任何想法,请帮助:)

于 2018-12-14T00:44:17.823 回答