Skip to content

Echo bot #3

@AdriG83

Description

@AdriG83

Hi,
congrats for your tutorial. I write your example

`import os, sys
from flask import Flask, request
from utils import wit_response
from pymessenger import Bot

app = Flask(name)

PAGE_ACCESS_TOKEN="xxx"

bot = Bot(PAGE_ACCESS_TOKEN)

@app.route('/', methods=['GET'])
def verify():
# when the endpoint is registered as a webhook, it must echo back
# the 'hub.challenge' value it receives in the query arguments
if request.args.get("hub.mode") == "subscribe" and request.args.get("hub.challenge"):
if not request.args.get("hub.verify_token") == "Magghy":
return "Verification token mismatch", 403
return request.args["hub.challenge"], 200

return "Hello world", 200

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

if data['object'] == 'page':
	for entry in data['entry']:
		for messaging_event in entry['messaging']:

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

			if messaging_event.get('message'):
				# Extracting text message
				if 'text' in messaging_event['message']:
					messaging_text = messaging_event['message']['text']
				else:
					messaging_text = 'no text'

				response = None

				entity, value = wit_response(messaging_text)
				if entity == 'libro':
					response = "Ok, I will send you the {} news".format(str(value))
				elif entity == 'luogo':
					response = "Ok, so you live in {0}. Here are top headlines from {0}".format(str(value))

				if response == None:
					response = "Non so cosa dirti"
					
				bot.send_generic_message(sender_id, response)

return "ok", 200

def log(message):
print(message)
sys.stdout.flush()

if name == 'main':
app.run(debug = True, port = 8000)`

But my bot continues to answer me with the phrases I write to him :(

What is my mistake?

Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions