skip to Main Content

TLDR; @ bottom

I asked the following question in the Facebook bugs section

NOTE: This is more of a platform design suggestion than a bug, as I failed to find a Chat API feedback portal
Currently I’m building a Chat bot that allows the user to track a goal. It will say something like “Did you go for a walk on July 12, 2016 ?” and have Yes/NO buttons below.
Currently in order to pass the intent, the day and the achievement boolean I need to template a string like this “==GOAL== achieved? <<<{goal_achieved}>>>, date tracked [[[{date_tracked}]]]” and use regex to capture the delimited variables. This is prone to parsing error in other cases where the templated strings in the payload are user-input variables i.e. if the ‘{goal_achieved}’ were replaced with the goal variable ‘>>meditated” then the regex that captures the templated variable could fail.
One could use the postback payload to store a JSON-encoded string but the problem with this is that the payload string gets logged into the user output and JSON strings are a bit ugly and confusing. The challenges I face could be easily remedied if the payload was not logged to the user Instead log the text for the button to help the user confirm the button was clicked.
If that is not possible, is there any other advice for encoding data into button payload ?

The following answer was offered (Mark Wiltse)

Hi Justin,
Unfortunately at this time our payload structure does not support the functionality that you are trying to implement. From my understanding you want to use the Payload to inform your backend if the user accomplished their ‘goal’ on that specific date. I would suggest that you create your payload response for the button on your end before passing it to us, which is basically the JSON idea that you had initially.
I know this is a bit cumbersome to handle but the payload response passed back is independent of the text that was provided with the messenger thread.
I would suggest that you also attempt to sanitize your strings if you are worried a user has previously provided you would cause an issue with your regex. You should be able to implement this functionality if the prior user data is sanitized to avoid any issues with regex/json parsing.
Since this is an implementation question I will have to close this report as Invalid. If you are still looking for additional insights and concrete tips for implementing this flow please post to our stack overflow where we have Facebook Engineers and a wide range of community members who also contribute.
http://facebook.stackoverflow.com/
Take care and best wishes with your messenger bot.
Mark

This sentence was particularly unclear:

I know this is a bit cumbersome to handle but the payload response
passed back is independent of the text that was provided with the
messenger thread.

TLDR;
Can anyone inform me of how to prevent the button from logging the payload string so that I can use it to pass JSON to my app without the user seeing it ?

2

Answers


  1. From my understanding you’re saying that when you press a button the PAYLOAD instead of the button’s text is showing up.

    Are you defining your buttons like this?

        {
          type: "postback",
          title: "View Details",
          payload: "details:12345"
        }
    

    I’d recommend removing any special characters that would mess with the parsing of your payload. As long as the special characters are not crucial to the user experience this is probably a fine solution.

    If this doesn’t solve your issue:

    Can you add a screenshot showing the button you are pressing, and the log message you are talking about? From my understanding you’re saying that when you press a button the PAYLOAD instead of the button’s text is showing up. That’s not the case for me, my buttons text shows up when I press a button.

    Login or Signup to reply.
  2. Make sure to comment out sendTextMessage() in your receivedPostback() call :

    function receivedPostback(event){
        sendTextMessage(senderID, event.postback.payload);
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search