1

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 ?

4

2 回答 2

2

sendTextMessage()确保在您的receivedPostback()通话中注释掉:

function receivedPostback(event){
    sendTextMessage(senderID, event.postback.payload);
}
于 2016-10-24T16:01:50.790 回答
1

据我了解,您是说当您按下按钮时,会显示 PAYLOAD 而不是按钮的文本。

你是这样定义你的按钮的吗?

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

我建议删除任何会干扰您的有效负载解析的特殊字符。只要特殊字符对用户体验不重要,这可能是一个很好的解决方案。

如果这不能解决您的问题:

您可以添加一个屏幕截图来显示您正在按下的按钮以及您正在谈论的日志消息吗?据我了解,您是说当您按下按钮时,会显示 PAYLOAD 而不是按钮的文本。对我来说不是这样,当我按下按钮时,我的按钮文本会显示出来。

于 2016-08-03T16:24:26.900 回答