Search code examples
javascriptfacebookbotsfacebook-messenger

Facebook Messenger Bot sharing structured message with postback button


I'm in the middle of reviewing Facebook messenger platform and can't find any info on particular subject. I want bot user to share a structured message with his contacts, which would bring contact back to a bot chat caring a context.

Sharing of structured message works well:

  1. bot response with message containing template with 'Share Button'
  2. click on button opens native share menu
  3. user selects contacts to share message with
  4. message is sent to contacts
  5. each contact receives message as original

All that is as explained in the doc: https://developers.facebook.com/docs/messenger-platform/send-api-reference/share-button

The next part of a puzzle is 'Postback Button' that can be added to a structured message template in the same way as 'Share Button' (explained here https://developers.facebook.com/docs/messenger-platform/send-api-reference/postback-button). Tap on 'Postback Button' sends metadata to a webhook. All fine with that as well...

Let's say I have a bot that does a songs search. User types part of lyrics and bot offers list of songs matching those. Each song is listed by bot as structured message which has 'Share Button' and 'Postback Button' called 'Like'. Idea is that such message is shared by user to his contacts. Idea behind 'Like' (Postback Button) is to be clicked by contact receiving a message. Each click on 'Like' should bring user to bot chat and execute postback. Logic behind postack is tracking of user's contacts who liked particular song.

All that works until point when contacted user clicks 'Like'. Click opens a bot chat (first time users see welcome info), but no postback is executed. The same is if I use 'URL Button' (with Messenger Extensions).

Is there a way to accomplish something like this?

Thx

Here's example of message with postback button I want to use:

var messageData = {
  recipient: {
    id: recipientId
  },
  message: {
    attachment: {
      type: "template",
      payload: {
        template_type: "generic",
        elements: [{
          title: "Shake it off",
          subtitle: "Lorem ipsum....",
          buttons: [{
            type: "web_url",
            title: "Watch video",
            url: "http...",
          }, {
            type: "postback",
            title: "Like",
            payload: "id=xyz",
          }, {
            type: "element_share",
          }]
        }]
      }
    }
  }
};

Solution

  • Messenger platform got updated and new feature providing exactly what I needed: https://developers.facebook.com/docs/messenger-platform/referral-params