Coder Social home page Coder Social logo

hayabhay / django-facebook-messenger-bot-tutorial Goto Github PK

View Code? Open in Web Editor NEW
71.0 7.0 51.0 9 KB

Code for my Tutorial on building a Facebook Messenger bot using Django/Python

Home Page: https://abhaykashyap.com/blog/post/tutorial-how-build-facebook-messenger-bot-using-django-ngrok

License: MIT License

Python 100.00%
facebook-messenger-bot django python ngrok tutorial

django-facebook-messenger-bot-tutorial's Introduction

Facebook Messenger Bot tutorial using Django/Python

This has the starter code for the tutorial I wrote on my Blog.

Tutorial: How to build a Facebook Messenger bot using Django, Ngrok

How to use

Run the following commands. You will need Python 2.7+/3.3+ and have Virtual Environment Wrapper setup.

git clone https://github.com/abhay1/django-facebook-messenger-bot-tutorial.git
cd django-facebook-messenger-bot-tutorial
mkvirtualenv bottutorial
pip install -r requirements.txt
cd yomamabot
python manage.py runserver

Follow the tutorial to setup Ngrok. Edit the VERIFY_TOKEN variable in django-facebook-messenger-bot-tutorial/yomamabot/fb_yomamabot/views.py to include the Verify token. It is set to 2318934571 as default that is used in the tutorial. This can be any token as long as it matches the one you tell Facebook.

Once you have your webhook setup, get your Page Access Token. Then set the PAGE_ACCESS_TOKEN variable in the file django-facebook-messenger-bot-tutorial/yomamabot/fb_yomamabot/views.py to your page access token.

django-facebook-messenger-bot-tutorial's People

Contributors

abhay1 avatar acjh avatar hayabhay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-facebook-messenger-bot-tutorial's Issues

Still Works this method

I'm trying to integrate facebook messenger in my website, but I'm curious that still this method works or not

Is it working with comments ?

Hi abhay !

I read your post, its very awesome and help me understand webhooks.
After this your post i have an question,
How to make this project work with comments and if i want to save all news even to db how i can do that's ?

Thanks so much Abhay !

Can't get user name

Hi!
When I run the code, it works fine until I send a message to the bot, when I get this error:

joke_text = 'Yo '+user_details['first_name']+'..!' + joke_text
KeyError: 'first_name'

And facebook returns this:

> {u'error': {u'message': u'Invalid OAuth access token.', u'code': 190, u'type': u'OAuthException', u'fbtrace_id': u'HcT2M7LgPTY'}}
> {u'error': {u'code': 100,
>             u'error_subcode': 2018001,
>             u'fbtrace_id': u'ANUjQzx/PUi',
>             u'message': u'(#100) No matching user found',
>             u'type': u'OAuthException'}}

So, I don't know what to do know, as user's name is really important for my idea.
Thanks in advice

self.request.GET['hub.verify_token'] error

def get(self, request, *args, **kwargs):
		try:
			print(self.request.GET)
			token = self.request.GET['hub.verify_token']
		except MultiValueDictKeyError:
			print("hhhhhhhhhh")
			token = False

		if token == VERIFY_TOKEN:
			return HttpResponse(self.request.GET['hub.challenge'])
		else:
			return HttpResponse('Error, invalid token')

it returned <QueryDict: {}>

I do not get "hub.verify_token" in get request when i open url in browser

I have downloaded and setup your code and I have set up ngrok also and configured app on facebookdeveloper site but after all configuration when I am going to open https://6bc98399.ngrok.io/fb_yomamabot/66d2b8f4a09cd35cb23076a1da5d51529136a3373fd570b122/, then it will throw error.

Internal Server Error: /fb_yomamabot/66d2b8f4a09cd35cb23076a1da5d51529136a3373fd570b122/
Traceback (most recent call last):
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/bottutorial/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/bottutorial/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/bottutorial/local/lib/python2.7/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/bottutorial/local/lib/python2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/bottutorial/local/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/bottutorial/local/lib/python2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.get(self, type(self))(*args2, **kwargs2)
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/yomamabot/fb_yomamabot/views.py", line 55, in dispatch
return generic.View.dispatch(self, request, *args, **kwargs)
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/bottutorial/local/lib/python2.7/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/yomamabot/fb_yomamabot/views.py", line 48, in get
if self.request.GET['hub.verify_token'] == VERIFY_TOKEN:
File "/home/sagar-p/Desktop/django-facebook-messenger-bot-tutorial/bottutorial/local/lib/python2.7/site-packages/django/utils/datastructures.py", line 85, in getitem
raise MultiValueDictKeyError(repr(key))
MultiValueDictKeyError: "'hub.verify_token'"

It is not getting anything in "self.request.GET"... It is getting "<QueryDict: {}>". Please help me to figureout this error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.