Facebook webhook event from defold with parameters

When the user selects a player from facebook context screen(invite to play), i got selected player id from the “choose_context” callback

local args = {
	minSize= 1,
	maxSize=10,
}
if type(args) == "table" then 
	args = json.encode(args)
end
fbinstant.choose_context(function(self,id, type)		
	print("choose_context",id, type)
end)

Now i need to pass that id using webhook event in FB. How I do it.

What do you mean by this? I’m not familiar with FB webhooks. Is this for a messenger bot?

yes, its for messenger bot.

I have no idea. Can you direct me to some official Facebook documentation describing exactly what it is you want to do and I’ll try to provide some support from a Defold perspective.

Bots: https://developers.facebook.com/docs/games/instant-games/guides/bots-and-server-communication#bots
Webhooks: https://developers.facebook.com/docs/messenger-platform/webhook

Dear britzl,
Do you have any working example defold project that I can use to create a bot with the example server that provide in “https://developers.facebook.com/docs/games/instant-games/guides/bots-and-server-communication#bots

You can’t send fb bot webhook manually. Facebook sends it automatically when player close a game.
You can only set parameters, which will be set to webhook as payload. Use method set_session_data for this. Usage example

1 Like

this is the player details when i called “fbinstant.get_players()”.

dmloader.js:1 1 = { --[[0x12714d0]]
dmloader.js:1 id = “2272139892825906”,
dmloader.js:1 name = “Chamika”,
dmloader.js:1 photo = “https://platform-lookaside.fbsbx.com/platform/instantgames/profile_pic.jpg?igpid=2272139892825906&height=200&width=200&ext=1556966489&hash=AeT-g6IbdVKs4JWv
dmloader.js:1 },
dmloader.js:1 2 = { --[[0x107fd60]]
dmloader.js:1 id = “2297697620300909”,
dmloader.js:1 name = “Cds”,
dmloader.js:1 photo = “https://platform-lookaside.fbsbx.com/platform/instantgames/profile_pic.jpg?igpid=2297697620300909&height=200&width=200&ext=1556966489&hash=AeROvXfcjV5I2aLU
dmloader.js:1 }
dmloader.js:1 }

my gameplay name is “Cds”, so I need to send a message to “Chamika” when game end. so i use ,

fbinstant.set_session_data(rxijson.encode({
	playerWon = true,
	opponent = self.game_data.players[self.opponent_index],
	score = 10,
}))

function to send data to the sever. but it not send message to the “Chamika”.

this is the backend code,

 function receivedGameplay(event) {
    // Page-scoped ID of the bot user
    var senderId = event.sender.id; 

    // FBInstant player ID
    var playerId = event.game_play.player_id; 

    // FBInstant context ID 
    var contextId = event.game_play.context_id;

    // Check for payload
    if (event.game_play.payload) {
        //
        // The variable payload here contains data set by
        // FBInstant.setSessionData()
        //
        var payload = JSON.parse(event.game_play.payload);

        // In this example, the bot is just "echoing" the message received
        // immediately. In your game, you'll want to delay the bot messages
        // to remind the user to play 1, 3, 7 days after game play, for example.
        sendMessage(senderId, null, "Message to game client: '" + payload.message + "'", "Play now!", payload);
    }
}

Use official facebook knowledge base for refrence
Hope there you’ll be able to find more authentic information

  1. Check you subscribed to bot.

  2. Did you get (on your server) validate webhook request when you setup you bot?

What’s the content of the payload? Can you log it and share?