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.

image8

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 Chatfuel.com

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.

image9

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. 

E.g. https://branded.mini-games.io/?php=landing@jz1l3W04Ne&campaign_no=6501

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

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

image1
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,

https://branded.mini-games.io/?php=landing@jz1l3W04Ne&campaign_no=6501&userid={{messenger user id}}

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

image7
5. Set UP AI:

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

I added AI Rule as example like below,

image5
6. Test your bot:

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

image4

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

image10

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.

image6

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

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

NameDescriptionSample
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:

NameDescriptionSample
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 imagehttps://branded.mini-games.io/upload/reward/f1GByiOHZZ9biLGd32jp.png
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";
    exit;
}
if (trim($playtime) == "") {
    echo "F : playtime is missed";
    exit;
}
if (trim($time) == "") {
    echo "F : time is missed";
    exit;
}
// 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