DEV Community

Cover image for Facebook ChatBot Using Flask

Posted on • Updated on

Facebook ChatBot Using Flask

first of all go here and login with your fb account
Also Install ngrok zip file
Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode

Image description
Fill the instructions According to you
Image description

Image description
That's it Now We Do Some code
create a folder and using pip install these Modules

pip install pymessenger

pip install requests

pip install flask
Enter fullscreen mode Exit fullscreen mode

Open your Folder And make a file name

from flask import Flask,request
import requests
from pymessenger import Bot

app =  Flask(__name__)


def handling_message(text):
    adjusted_msg = text
    if adjusted_msg == 'hi' or adjusted_msg == 'Hi':
        response = 'hey'
    elif adjusted_msg == "what's up" or adjusted_msg == "what's up":
        response = "i'm Great"
        response = "it's pleasure to talk with you,Thank you."
    return response

@app.route('/', methods = ["POST","GET"])

def web_hook():
    if request.method == "GET":
        if request.args.get('hub.verify.token') == VERIFY_TOKEN:
            return request.args.get('hub.challenge')

                return 'Unable To Connect Meta'
    elif request.method == 'POST':
        data = request.json
        process = data['entry'][0]['messaging']
        for msg in process:
            text = msg['message']['text']
            sender_id = msg['sender']['id']
            response = handling_message(text)
        return 'Message Delivered'

![Image description](

if  __name__ == '__main__':

Enter fullscreen mode Exit fullscreen mode

name anything about verify token
Generate page access token and paste above

Now Extract ngrok and paste it in your Workspace

Image description

and ngrok As An Administrator
put this cmd
and Hit Enter

ngrok.exe http 5000
Enter fullscreen mode Exit fullscreen mode

now you are connected with it
from here copy https that end with .io
and paste it here with token name and save

Image description
Restart your app Build again And You Are Good To Go

Top comments (0)