def test_bot_output_format(): message = { "event": "bot", "text": "Hello!", "data": { "image": "http://example.com/myimage.png", "attachment": "My Attachment", "buttons": [ {"title": "yes", "payload": "/yes"}, {"title": "no", "payload": "/no", "extra": "extra"}, ], "elements": [ { "title": "element1", "buttons": [{"title": "button1", "payload": "/button1"}], }, { "title": "element2", "buttons": [{"title": "button2", "payload": "/button2"}], }, ], "quick_replies": [ { "title": "quick_reply1", "buttons": [{"title": "button3", "payload": "/button3"}], }, { "title": "quick_reply2", "buttons": [{"title": "button4", "payload": "/button4"}], }, ], }, } from rasa.shared.core.events import Event bot_event = Event.from_parameters(message) assert isinstance(bot_event, BotUttered) formatted = interactive.format_bot_output(bot_event) assert formatted == ( "Hello!\n" "Image: http://example.com/myimage.png\n" "Attachment: My Attachment\n" "Buttons:\n" "1: yes (/yes)\n" '2: no (/no) - {"extra": "extra"}\n' "Type out your own message...\n" "Elements:\n" '1: element1 - {"buttons": ' '[{"payload": "/button1", "title": "button1"}]' '}\n2: element2 - {"buttons": ' '[{"payload": "/button2", "title": "button2"}]' "}\nQuick replies:\n" '1: quick_reply1 - {"buttons": ' '[{"payload": "/button3", "title": "button3"}' ']}\n2: quick_reply2 - {"buttons": ' '[{"payload": "/button4", "title": "button4"}' "]}" )
def test_bot_output_format(): message = { "text": "Hello!", "data": { "image": "http://example.com/myimage.png", "attachment": "My Attachment", "buttons": [ { "title": "yes", "payload": "/yes" }, { "title": "no", "payload": "/no", "extra": "extra" }, ], "elements": [ { "title": "element1", "buttons": [{ "title": "button1", "payload": "/button1" }], }, { "title": "element2", "buttons": [{ "title": "button2", "payload": "/button2" }], }, ], "quick_replies": [ { "title": "quick_reply1", "buttons": [{ "title": "button3", "payload": "/button3" }], }, { "title": "quick_reply2", "buttons": [{ "title": "button4", "payload": "/button4" }], }, ], }, } formatted = interactive.format_bot_output(message) assert formatted == ("Hello!\n" "Image: http://example.com/myimage.png\n" "Attachment: My Attachment\n" "Buttons:\n" "1: yes (/yes)\n" '2: no (/no) - {"extra": "extra"}\n' "Elements:\n" '1: element1 - {"buttons": ' '[{"payload": "/button1", "title": "button1"}]' '}\n2: element2 - {"buttons": ' '[{"payload": "/button2", "title": "button2"}]' "}\nQuick replies:\n" '1: quick_reply1 - {"buttons": ' '[{"payload": "/button3", "title": "button3"}' ']}\n2: quick_reply2 - {"buttons": ' '[{"payload": "/button4", "title": "button4"}' "]}")
def test_bot_output_format(): message = { "text": "Hello!", "data": { "image": "http://example.com/myimage.png", "attachment": "My Attachment", "buttons": [{ "title": "yes", "payload": "/yes" }, { "title": "no", "payload": "/no", "extra": "extra" }], "elements": [{ "title": "element1", "buttons": [{ "title": "button1", "payload": "/button1" }] }, { "title": "element2", "buttons": [{ "title": "button2", "payload": "/button2" }] }], "quick_replies": [{ "title": "quick_reply1", "buttons": [{ "title": "button3", "payload": "/button3" }] }, { "title": "quick_reply2", "buttons": [{ "title": "button4", "payload": "/button4" }] }] } } formatted = interactive.format_bot_output(message) assert formatted == ( "Hello!\n" "Image: http://example.com/myimage.png\n" "Attachment: My Attachment\n" "Buttons:\n" "1: yes (/yes)\n" "2: no (/no) - {\"extra\": \"extra\"}\n" "Elements:\n" "1: element1 - {\"buttons\": " "[{\"payload\": \"/button1\", \"title\": \"button1\"}]" "}\n2: element2 - {\"buttons\": " "[{\"payload\": \"/button2\", \"title\": \"button2\"}]" "}\nQuick replies:\n" "1: quick_reply1 - {\"buttons\": " "[{\"payload\": \"/button3\", \"title\": \"button3\"}" "]}\n2: quick_reply2 - {\"buttons\": " "[{\"payload\": \"/button4\", \"title\": \"button4\"}" "]}")