Skip to content Skip to main navigation Skip to footer

How to integrate your campaign into the Facebook Messenger bot / Chatbot?

1. Introduction

This article explains how to integrate your Campaign to Messenger or Chatbot.

Please note that the Studio does not support the making of a Chatbot itself.

We highly recommend using Chatfuel, if you want to create a Facebook bot or Telegram bot.

Otherwise, you need to develop the chatbot server using server-side languages such as Python, Node.js, PHP, Java or whatever you want.

2. Create a Campaign for Messenger

First, you will need to create a Campaign for where would you like the game to be integrated and any type of purpose. We recommend the Daily Reward type for the Messenger target, but other types of purpose (Ranking Basis, Lucky Draw and Instant Win) can also be used for the Messenger target.


After you have selected where you would like the game to be integrated and the purpose, you will move to the setting pages. You can set your Campaign options here.

Note: the campaign should be published if you integrate it to the Facebook bot.

3. Create a Facebook bot using

You will need to create your Facebook bot first, if you don’t have it yet. To set up your bot, following this guide when you create it in your server-side language.

In this article, we are using Chatfuel to create the Facebook bot. It is quite easy to create. Please see the Chatfuel guide page here.


4. Integrate your Campaign to the Facebook bot

Once the Facebook bot is ready, you can integrate your Campaign into your Facebook bot.

There are only 2 processes to integrate it:

4.1. Call your Campaign with userid parameter

1. Move to Campaign manage page > Page Settings > Log-in
2. Copy your Campaign URL. 


3. Create a Message Block in your Bot Structure in Chatfuel Dashboard:

You can add a related image and text to the Message Block.

4. Paste the Campaign URL to the Link with userid parameter:

Once you add the text card, click the ADD BUTTON and paste the Campaign URL with the userid parameter. The value of parameter should be Facebook ID, Chatfuel supports the {{messenger user id}} option for sending the Facebook ID.

So, you can insert the Campaign URL like below example,{{messenger user id}}

You can call your Campaign anywhere in your Facebook bot like this way.

5. Set UP AI:

Now, you need to set AI Rule for the Campaign Block.

I added AI Rule as example like below,

6. Test your bot:

When you have finished adding the AI Rule, click the TEST THIS CHATBOT button at the top-right.


Type the play game, then you can get the PLAY button for playing your Campaign.


4.2. Return your game score and information to your System

You can return the game results from the Campaign to your System. Then, you can handle and use this information as you like.

For example,

  • Give some coupons to a user who played the game.
  • Save some Mileages to a user who got more than 1000 score.
  • Give a coffee coupon to a user who played 10 times total.

To get the game results, you will need to develop a program on your server. Then, paste the URL into the Webhook URL in Campaign manage page > Return Game Result. You can also select the data format as plain text or json.


Different game results will be returned according to the selected purpose.

If your Campaign is Ranking Basis/Lucky Draw/Daily Reward type:

useridunique ID for userT4g4fLTa or james
tx_idunique ID for each game playing234234
timedatetime which a game player tried to play2015-04-10 06:39:23
scorescore which a game player got3500
playtimetime period(seconds) which a game player played20

If your Campaign is Instant Win type:

useridunique ID for userT4g4fLTa or james
tx_idunique ID for each game playing234234
timedatetime which a game player tried to play2015-04-10 06:39:23
reward_imagereward image
reward_itemreward itemCoffee

Parse example by PHP:

// getting data
isset($_POST['userid']) ? $userid = $_POST['userid'] : $userid = '';
isset($_POST['tx_id']) ? $tx_id = $_POST['tx_id'] : $tx_id = '';
isset($_POST['score']) ? $score = $_POST['score'] : $score = '';
isset($_POST['playtime']) ? $playtime = $_POST['playtime'] : $playtime = '';
isset($_POST['time']) ? $time = $_POST['time'] : $time = '';
// checking validity
if (trim($score) == "") {
    echo "F : score is missed";
if (trim($playtime) == "") {
    echo "F : playtime is missed";
if (trim($time) == "") {
    echo "F : time is missed";
// saving data into database
$sql  = "insert into playing_log ('tx_id', 'userid', 'time', 'score', 'playtime') values ('".$tx_id."', '".$userid."', '".$time."', '".$score."', '".$playtime."');";
//echo $sql;
// connection DB
// insert data
// result of saving
if ($result) {
    echo "S";
else {
    echo "F : DB failure";
Submit a query

Leave us a message