[英]Facebook messenger bot not sending messages (Python/Django)
[英]Messenger bot on python
我正在使用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向機器人發送郵件的方式收到一個錯誤。
好吧,我沒有找到更好的解決方案。
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
我現在想使用時間戳記,但老實說不知道如何。 因此,例如,如果有一個用戶,您很長時間沒有發短信,則會收到“歡迎回來,我們想念您”消息。
我不確定這段代碼如何與同時發短信的人一起使用。 由於我使用了全局變量,可能是所有的越野車。 如果您有任何想法,請幫助:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.