The code for it is as below:Ĭonst processMessage = require(‘./helpers/processMessage’) The second endpoint too goes in the controller folder and is called messageWebhook.js. Do keep it in mind as you will need it later while setting up the Facebook app. You can change the string called “mynewbot” to anything you wish. The code for it is:Ĭonst hubChallenge = req.query Ĭonst verifyTokenMatches = (req.query = ‘mynewbot’) The first endpoint should be created in controllers and be named verification.js. You can name them controllers and helpers. To simplify things, separate your code in two folders. The second endpoint is for all the other messages that you receive from Facebook Messenger. This token shall be matched with the webhook server’s response to ensure it’s the same server. You’ll need to get a token as you’re connecting a Facebook page with the webhook server. The first is for the initial verification of Facebook. If it’s working, you should get a message that says, “Webhook server is listening, port 3000.” To check if it’s working, you can run the following in the terminal. After that, start the Express server and set the listening to port 3000. You’ll also create a middleware called body-parser for parsing new incoming requests.įor this, you need to type the following in the terminal:Īfter the installation, go to the directory and make a file called index.js. Once you’ve done this, you can install Express.js to create a server. Start by creating a directory called “Facebook Messenger chatbot.” On creating this, you can go to the terminal and initialize Node.js. To create this webhook, you can use Express.js. Unlike other APIs, it continuously keeps sending data to other applications. You need to start by creating a webhook that provides other apps with real-time data. Hence, we’ll take a look at how you can develop your Messenger chatbot using it.
0 Comments
Leave a Reply. |