Send private messages to facebook page followers php sdk

Facebook recently announced a Bot platsize for it’s Messenger which provides businesses & individuals another way khổng lồ communicate with people.

Bạn đang xem: Send private messages to facebook page followers php sdk

What is a Chat bot?

A computer program designed to lớn simulate conversation with human users, especially over the Internet.

Chat bot in PHP

When I heard of it, my very first thought was to a bot in PHP.. I started to find some SDK in this regard released by Facebook but none was present. I headed over lớn documentation which provided good information for starters.

Ok! so without wasting further time, let’s build our first Bot


In order to lớn create an Fb bot you will need two things lớn host your bot: A Facebook Page which will be like Home of Bot, People will visit the page, cliông xã on Message option lớn Interact with your bot. For example, suppose Pizza Hut introduce a bot for order related operations. What could they bởi that they integrate or host their bot on their official page, a người can just cliông chồng on Message button and sover messages to lớn order a Pizza, get new giao dịch etc and they will get messages as if some human representatives is responding to lớn them. It all depends how efficient a bot is. Facebook puts no limitation in this regard.

I am going khổng lồ create a Time bot which will tell you current time Time API that provides different options khổng lồ retrieve sầu time. For our bot, we are just fetching latest(NOW) time. I will go step by step:

Step 1: Create Facebook Page:

I am going lớn create Bot’s Page first, this page will actually be the entry point for communication for the bot lớn interact with your page fans/users. Do note that it is not necessary to lớn create a separate page only for Bot purpose. You may use existing Fan page for this purpose.  For sake of this tutorial I am assuming that you never created a page before. Visit and you will see something lượt thích this(as of April, 2016):


I picked Entertainment option. In next steps it asks different options which you can always skip.

Xem thêm: Twin Software Solutions Is Hiring A Nhân Viên Triển Khai Phần Mềm Twin

Alright! so my page is ready and something lượt thích should be visible for you as well:


Step 2: Create Facebook App:

Alright, go to và cliông chồng on Add a New App button. Make sure you have a developer account otherwise you will not be able lớn access developer dashboard. 


When you clichồng on it it shows a window và asks you what kind of tiện ích are you going khổng lồ make. I picked Basic Setup given at bottom. I entered required information; Display Name và Liên hệ Email and hit Create App ID button.


After Captcha you will be redirected to your App Page where you will be seeing details.


On left side bar you will see an option of Messenger. When you cliông chồng on it, it shows introduction of Messenger Platsize and why và how these bots will be helpful.


Cliông chồng on Get Started và it will show a New Dashboard page related khổng lồ your newly created app that’s going to lớn be hooked with Messenger platsize.


Now we need to bởi vì a few things for setting up the bot. As you can see, you are being asked a few things; Access Token/Page Token so that Facebook can know where bởi vì you want khổng lồ host bot, Webhooks, your script URL that will be receiving messages from your users và responding them. It will also be hold the súc tích of your bot & Permissions that is, what this bot should be able to persize when communicating with users. Ok first, phối the page which you just created. I am selecting TimBot. Since I, as a normal Facebook User going to lớn use this page very first time, it will ask for Permissions as it normally asks.

Xem thêm: Chức Năng Của Phần Mềm Gx Works2, Chức Năng Của Phần Mềm Gx


Once all goes well you would get your Page Token like this, save it somewhere as this will be used as access_token while sending messages.


Now we have sầu to mix our Webhook. Facebook asks you khổng lồ cài đặt an https:// URL which means, you simply can’t use localhost while developing. You can either upload your script somewhere which allows SSL based requests or.. you can use some tunneling tool that will pass on your localhost message khổng lồ outer world. Luckily such tools are available and they are FREE as well. I’d recommover nGrok for this purpose. Once it’s unzipped, go to lớn the folder and run the command:

Chuyên mục: