Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echo bot #3

Open
AdriG83 opened this issue Oct 24, 2017 · 2 comments
Open

Echo bot #3

AdriG83 opened this issue Oct 24, 2017 · 2 comments

Comments

@AdriG83
Copy link

AdriG83 commented Oct 24, 2017

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

@nikhilkumarsingh
Copy link
Owner

Can you please elaborate your problem? What input are you giving and what is the output?

@AdriG83
Copy link
Author

AdriG83 commented Oct 24, 2017

Sorry, I solved the problem of echo.
I want to create a conversational chat bot not connected with the news.
I have to manage all the answers of my bot from app.py with the def webook() or with the "Stories" tab of Wit.ai?
The intents Wit of my bot will be many.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants