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

Hi @JiteshGaikwad,

I am using your chat widget, In that you gave a java script function to get quick replies from rasa, If I gave more quick replies I am getting those in single line, I don’t want to get them in single line, according to screen I want, please help me on that to change java script function.

I am very very poor in UI developing.

@mounika2 I have designed those quick replies to be placed horizontally, I can’t change those designs as those chips have designed to scroll.

@JiteshGaikwad, okay thank you for your information.

Hi @JiteshGaikwad,

To set the default welcome message you define action_trigger() function in your script, there you define hasOwnProperty as messages how we define that utter_message in rules or stories, here we are not suposed to define any intent right. please help me on that.

Thanks in advance.

Hi @JiteshGaikwad

I am define my action_welcome like this

class ActionWelcome(Action):

def name(self) -> Text:

    return "action_welcome"

def run(self, dispatcher: CollectingDispatcher,

        tracker: Tracker,

        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

    dispatcher.utter_message(text="Hi, I am Gamma. Welcome to MauveStay.")

    dispatcher.utter_message(text="What can I help you with today? Choose an option")

    dispatcher.utter_message(template="utter_greet")

    return []

I want to trigger this action as bot to start the conversation in action_trigger function in JavaScript file provided by you.

If I try to replace action_name as action_welcome

I am getting error like this

2021-01-29 11:29:08 DEBUG rasa.core.actions.action - Calling action endpoint to run action ‘action_welcome’. 2021-01-29 11:29:11 DEBUG rasa.core.processor - Policy prediction ended with events ‘[]’. 2021-01-29 11:29:11 DEBUG rasa.core.lock_store - Deleted lock for conversation ‘mounika’. 2021-01-29 11:29:11 DEBUG rasa.server - Traceback (most recent call last): File “c:\python38\lib\site-packages\rasa\server.py”, line 843, in execute_action await app.agent.execute_action( File “c:\python38\lib\site-packages\rasa\core\agent.py”, line 564, in execute_action return await processor.execute_action( File “c:\python38\lib\site-packages\rasa\core\processor.py”, line 341, in execute_action await self._run_action(action, tracker, output_channel, nlg, prediction) File “c:\python38\lib\site-packages\rasa\core\processor.py”, line 770, in _run_action self._log_action_on_tracker(tracker, action, events, prediction) File “c:\python38\lib\site-packages\rasa\core\processor.py”, line 833, in _log_action_on_tracker tracker.update(action.event_for_successful_execution(prediction)) File “c:\python38\lib\site-packages\rasa\core\actions\action.py”, line 252, in event_for_successful_execution self.name(), prediction.policy_name, prediction.max_confidence File “c:\python38\lib\site-packages\rasa\core\policies\policy.py”, line 487, in max_confidence return max(self.probabilities, default=0.0) TypeError: ‘>’ not supported between instances of ‘str’ and ‘float’

2021-01-29 11:29:11 ERROR rasa.server - An unexpected error occurred. Error: ‘>’ not supported between instances of ‘str’ and ‘float’