bionbeam.blogg.se

Use python to make facebook chatbot
Use python to make facebook chatbot













use python to make facebook chatbot
  1. #Use python to make facebook chatbot install#
  2. #Use python to make facebook chatbot code#

#uses PyMessenger to send response to userĭef send_message(recipient_id, response): #chooses a random message to send to the user #if they match, allow the request, else return an error #take token sent by facebook and verify it matches the verify token you sent Send_message(recipient_id, response_sent_nontext) #if user sends us a GIF, photo,video, or any other non-text item Send_message(recipient_id, response_sent_text) #Facebook Messenger ID for user so we know where to send response back to # get whatever message a user sent the bot #if the request was not get, it must be POST and we can just proceed with sending a message back to user That confirms all requests that your bot receives came from Facebook.""" """Before allowing people to message your bot, Facebook has implemented a verify token #We will receive messages that Facebook sends our bot at this methods=) #Python libraries that we need to import for our bot Expanding on our basic Flask app, we will go to our receive_message function in app.py and add the following lines of code:

use python to make facebook chatbot

In our case, we will use GET requests when Facebook checks the bot’s verify token. To make the bot, we first need to handle two types of requests, GET and POST. Since we now have the necessary Python libraries installed, it’s time to write our bot.įor the purposes of the bot we’ll make in this guide, we’ll stick to using a small Python list with a few responses. To handle sending messages back to a user who communicates with our bot, we’ll be using the PyMessenger library to handle sending responses to users. To build this bot, we will build off of this basic structure in order to handle a user’s request and return a response to them. If you navigate to the link given from running the app (in this example ) in a browser, you will see a page load that says “Hello World!” With just these few lines of code, we’ve created a web application that displays “Hello World” to any user who goes to the specified link.

#Use python to make facebook chatbot install#

Once you have downloaded the above files, you need to install the following libraries: To make this bot, you need to make sure you have a few things installed:

#Use python to make facebook chatbot code#

If you’re interested into digging the code for the bot, you can fork it and play with it via GitHub. Specifically, we’ll be making a basic version of Black Girl Magic Bot, a Facebook Messenger bot that sends users images, playlists, and generally uplifting messages to remind them just how amazing they are. We’ll cover everything from the basics of how bots work to building our own basic Facebook Messenger bot. However, I quickly dug into the Facebook Messenger documentation and began learning how with a bit of Python 3 and Flask, one could get a bot up and running in no time. When I first learned about bots, I never imagined I would be able to make one on my own. Bots can be an amazing product that allow people to create new experiences, from reporting personal news to delivering women’s healthcare information.















Use python to make facebook chatbot