JSON for Custom Request not working, it works on other platforms

(Evelyn Cho) #1

Hello Everyone!

I’m migrating my bots from Chatfuel to Flow XO (woot!) and I’m having troube maintaining their functionality.

I make an HTTP request to a webhook and I represent the data that is returned with a Custom Request, but I keep getting error messages (#100) Invalid keys “text” were found in param “name_placeholder”).

{
    "message":{
        "text":response
    },
    {
        "attachment":{
            "type":"template",
            "payload":{
                "template_type":"generic",
                "image_aspect_ratio":"horizontal",
                "elements":elements
            }
        }
    }
}

If I only use the following part, it works. It also works with only the text message:

{
    "attachment":{
        "type":"template",
        "payload":{
            "template_type":"generic",
            "image_aspect_ratio":"horizontal",
            "elements":elements
        }
    }
}

I can’t make it work, and I would like to send a message and also the content at the same time. Is there a way to make it work? Am I missing something?

Thank you very much for your help!!!
Evelyn

(Karen Barker) #2

Hi Evelyn,

Our custom request function automatically includes the “message” headers and therefore when you’re running this Facebook are finding these duplicated and giving you the error message. If you add the “text”:“response” line to the payload of the attachment then you will recieve the message along with the content. :thumbsup:

1 Like
(Evelyn Cho) #3

Hello Karen,

First of all, thank you for your response. :slight_smile:

I tried adding “text”:response to the payload, but nothing is displayed. I get the following error “(#100) Invalid keys “text” were found in param “name_placeholder”.”

I tried multiple times, but it only works if there is only “text”, or only the rest. When they’re both together in the payload, I get that error and nothing is displayed.

{
    "attachment":{
        "type":"template",
        "payload":{
            "text":response,
            "template_type":"generic",
            "image_aspect_ratio":"horizontal",
            "elements":elements
        }
    }
}

Do you know what I could be possibly doing wrong? Thank you very much for your help!
Evelyn

(Daniel Beckett) #4

Hi @Evelyn

In your request are you populating text and elements with data from your outputs?

(Evelyn Cho) #5

Hi @DanielBeckett,

The following snippet of code is the body of the output of the HTTP request as seen from the logs. I then use {{make_a_http_request.body}} in a Make Custom Request action, but I get that error:

{
    "attachment":{
        "type":"template",
        "payload":{
            "text":"Ok, I have something for you:",
            "template_type":"generic",
            "image_aspect_ratio":"horizontal",
            "elements":[
                {
                    "title":"Porsche\u2019s EV lead takes shots at Tesla while hyping the Mission E",
                    "image_url":"https://tctechcrunch2011.files.wordpress.com/2018/02/2porschemissione.jpg?w=780&h=600",
                    "subtitle":"2018-02-28",
                    "default_action":{
                        "type":"web_url",
                        "url":"https://techcrunch.com/2018/02/28/porsches-ev-lead-takes-shots-at-tesla-while-hyping-the-mission-e/"
                    },
                    "buttons":[
                        {
                            "type":"web_url",
                            "url":"https://techcrunch.com/2018/02/28/porsches-ev-lead-takes-shots-at-tesla-while-hyping-the-mission-e/",
                            "title":"View on Web"
                        },
                        {
                            "type":"element_share"
                        }
                    ]
                },
                {
                    "title":"Tesla wants to install chargers at the office",
                    "image_url":"https://tctechcrunch2011.files.wordpress.com/2016/06/shutterstock_284409203a.jpg?w=780&h=600",
                    "subtitle":"2018-02-23",
                    "default_action":{
                        "type":"web_url",
                        "url":"https://techcrunch.com/2018/02/23/tesla-wants-to-install-chargers-at-the-office/"
                    },
                    "buttons":[
                        {
                            "type":"web_url",
                            "url":"https://techcrunch.com/2018/02/23/tesla-wants-to-install-chargers-at-the-office/",
                            "title":"View on Web"
                        },
                        {
                            "type":"element_share"
                        }
                    ]
                }
            ]
        }
    }
}

Thank you,
Evelyn

(Daniel Beckett) #6

If you remove the line for:
"text":"Ok, I have something for you:",

It looks like it should work. Can you give that a try?

(Evelyn Cho) #7

Hi @DanielBeckett, thank you for your reponse.

It does work without that line, but I want to send both the text message and the elements, @KarenBarker suggested I add that line there because the code that I posted in my first post didn’t work.

Is that a limitation of the Make Custom Request action?

Thank you!
Evelyn

(Karen Barker) #8

Hi @Evelyn ,

Sorry it looks like I was wrong about you being able to put text in the payload. Certain Facebook templates do allow this but it looks like the generic template doesn’t. :disappointed:

As a separate note if you are happy setting up the HTTP request there is no reason to need to migrate this to a custom request. The Custom request really is just a slightly simpler to set up form of the HTTP request.

From looking further at the Facebook API it doesn’t look like it is possible to send both a message and an attachment in a single request - they respond with the error “Only one of the text, attachment, and dynamic_text fields can be specified”.

Have you tried using the Send a Message action followed by a card (or custom request of the attachment section) does this not achieve what you’re hoping for and if not can you please share a screen shot showing the differences?

Thanks.

(Evelyn Cho) #9

Hi @KarenBarker, thank you for your response. Don’t worry about that! :wink:

If find “Send a Message” and “Send a Card” very limited and unsuitable for this application. When I make the HTTP request, “text” and “content” are populated with both text and content that depend on what the user asks, as shown in my last snippet of code, (it’s a search bot). And I use" Make Custom Request" to represent that data because I haven’t found a different way to do it. Is there another way?

Thank you!
Evelyn

(Daniel Beckett) #10

Hi @Evelyn

If you still have the data available as outputs in your flow you could insert them into messages or cards using the ‘xo’ icon. Could you use the same outputs being passed into your custom request and instead add them to a card?

Thanks,
Dan

(Evelyn Cho) #11

Hi @DanielBeckett, the number of cards I want to show is not defined, it depends on the search results. I believe the “Send a Card Set” action is not very suitable for this implementation since it appears I have to define the number of cards in advance.

I guess what I’ll do is make 2 consecutive calls and return 2 versions of the JSON: one with the message and one with the card set. That way I can use those 2 outputs in a “Send a Message” and “Make Custom Request” actions respectively.

Thank you!
Regards.

(Karen Barker) #12

Hi Evelyn,

A card set can include a maximum of 10 cards. Whilst you would need to set these up in advance using Data Outputs, if for example the last 3 cards returned null values from the JSON they would not be displayed to the user.