Create a Facebook Chatbot

Create a Facebook Chatbot

It's not hard at all to make your own chatbot. Adding AI is a slightly different story, but for now we want to get the basic mechanics of a chatbot for Facebook's Messenger going.

Make a native Facebook Chatbot in 20 minutes. We'll write some server-side code, host it on Heroku, and then connect it to Facebook.

As usual, the brilliant folks at Katacoda have a playground available where you can test this code on a live Node.js server. Visit and paste the code below to get started with your 1st Facebook chatbot. Let us know in the comments how it went.

'use strict'

const express = require('express')
const bodyParser = require('body-parser')
const request = require('request')

const app = express()

app.set('port', (process.env.PORT || 5000))

// Allows us to process the data
app.use(bodyParser.urlencoded({extended: false}))


app.get('/', function(req, res) {
	res.send("Hi I am a chatbot")

let token = ""

// Facebook 

app.get('/webhook/', function(req, res) {
	if (req.query['hub.verify_token'] === "blondiebytes") {
	res.send("Wrong token")
})'/webhook/', function(req, res) {
	let messaging_events = req.body.entry[0].messaging
	for (let i = 0; i < messaging_events.length; i++) {
		let event = messaging_events[i]
		let sender =
		if (event.message && event.message.text) {
			let text = event.message.text
			sendText(sender, "Text echo: " + text.substring(0, 100))

function sendText(sender, text) {
	let messageData = {text: text}
		url: "",
		qs : {access_token: token},
		method: "POST",
		json: {
			recipient: {id: sender},
			message : messageData,
	}, function(error, response, body) {
		if (error) {
			console.log("sending error")
		} else if (response.body.error) {
			console.log("response body error")

app.listen(app.get('port'), function() {
	console.log("running: port")

Here are the links to anything you might need to pull this off:

Download NPM/Node.js:
Download Sublime:
Sign up for GitHub:
Download Git:
Sign up for Heroku:
Download Heroku Command Line Tools:
Curl: curl -X POST ""

*Create a Facebook Chatbot*

Learn how to create your own Facebook Messenger chatbot with video tutorials, code samples ... the easy way.

#ai #ArtificialIntelligence
Deep Learning 101

Deep Learning 101

Hello World - Machine Learning Recipes #1

Hello World - Machine Learning Recipes #1