Is there any example of utter_custom_json() method?

I am trying to setup facebook quick_replies, I found out that there are methods here, but it does not seem to work yet.

This is what my action looks like, which should generate quick replies, but it does not. Instead, the bot does not respond.

    """Stop Action"""
    def name(self):
        return "action_stop_sub"

    def run(self, dispatcher, tracker, domain):
        user_name = tracker.get_slot('name')
        response = {"message":{"text":"Here is a quick reply!","quick_replies":[{"content_type":"text","title":"Cool","payload":"awesome","image_url":"http://example.com/img/green.png"},{"content_type":"text","title":"Not cool","payload":"Oh no","image_url":"http://example.com/img/red.png"}]}}
        dispatcher.utter_custom_json(response)
        return [SlotSet('subscribed', False)]

If I use utter_message method, as described here, It correctly prints the JSON.

Can someone please share their working example?

Thanks Jitesh, I tried both of them. But not sure what the JSON payload or the YML format should be for Quick Replies - Messenger Platform - Documentation - Facebook for Developers.

I tried several different formats, this is one of them: https://gist.githubusercontent.com/Jasmin25/6bb30a2c52903dbc33935360696cc178/raw/911ed562bb11b3cfe430ffc2488fa3c6c4c25a7f/domain.yml

But I get following error:

rasa_1_8564a5b6e7c6 | 2019-06-10 14:01:40 ERROR    rasa.core.nlg.template  - Failed to fill utterance template '{'custom': {'message': {'quick_replies': [{'content_type': 'text', 'image_url': 'http://example.com/img/red.png', 'payload': '/start_subscription', 'title': 'Start'}, {'content_type': 'text', 'image_url': 'http://example.com/img/red.png', 'payload': '/stop_subscription', 'title': 'Stop'}], 'text': 'Here is a quick reply!'}}}'. Tried to replace 'text' but could not find a value for it. There is no slot with this name nor did you pass the value explicitly when calling the template. Return template without filling the template.
rasa_1_8564a5b6e7c6 | Traceback (most recent call last):
rasa_1_8564a5b6e7c6 |   File "/usr/local/lib/python3.6/site-packages/rasa/core/nlg/template.py", line 114, in _fill_template_text
rasa_1_8564a5b6e7c6 |     text = re.sub(r"{([^\n]+?)}", r"{0[\1]}", template["text"])
rasa_1_8564a5b6e7c6 | KeyError: 'text'

hey @Jasmin25 according to this method:

did you tried send ur message in this way:

message ="Here is a quick reply!"

quick_replies=[{"content_type":"text","title":"Cool","payload":"awesome","image_url":"http://example.com/img/green.png"},{"content_type":"text","title":"Not cool","payload":"Oh no","image_url":"http://example.com/img/red.png"}]

send_quick_replies(recipient_id,message,quick_replies)

I am using Docker container, so can’t call that method directly into actions.py.

hey @Jasmin25 you can refer this thread it will help you:

1 Like