codeforequity-at / botium-core

The Selenium for Chatbots - Bots Testing Bots
https://www.botium.ai
MIT License
229 stars 64 forks source link

how to deal with card response in simplerest mode? #286

Closed dShreya1701 closed 5 years ago

dShreya1701 commented 5 years ago

My bot response is a card. For eg. I want to know the flight timing so it is giving responses like departure time, arrival time, destination, flight name etc on a card.....so How can I deal with this kind of response?

codeforequity-at commented 5 years ago

Can you please attach a sample of how the JSON response actually looks like ?

codeforequity-at commented 5 years ago

news ?

piotrjak commented 5 years ago

I have the same problem. My response contains Adaptive Cards. Can I test them in simplerest mode? My response looks like this:

{
    "payload": {
        "attachments": {
            "adaptiveCards": [
                {
                    "type": "AdaptiveCard",
                    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                    "version": "1.0",
                    "actions": [],
                    "body": [
                        {
                            "type": "ColumnSet",
                            "columns": [
                                {
                                    "type": "Column",
                                    "items": [
                                        {
                                            "type": "Image",
                                            "url": "http://url.photos.s3.amazonaws.com/cris_p/2/4036632-0.jpg",
                                            "horizontalAlignment": "center",
                                            "size": "medium"
                                        }
                                    ]
                                },
                                {
                                    "type": "Column",
                                    "items": [
                                        {
                                            "type": "TextBlock",
                                            "text": "USD 322,900",
                                            "weight": "bolder",
                                            "size": "medium"
                                        },
                                        {
                                            "type": "TextBlock",
                                            "text": "601 XD St",
                                            "isSubtle": true
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                },
                {
                    "type": "AdaptiveCard",
                    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                    "version": "1.0",
                    "actions": [],
                    "body": [
                        {
                            "type": "ColumnSet",
                            "columns": [
                                {
                                    "type": "Column",
                                    "items": [
                                        {
                                            "type": "Image",
                                            "url": "http://URL.photos.s3.amazonaws.com/cris_p/7/4067477-0.jpg",
                                            "horizontalAlignment": "center",
                                            "size": "medium"
                                        }
                                    ]
                                },
                                {
                                    "type": "Column",
                                    "items": [
                                        {
                                            "type": "TextBlock",
                                            "text": "USD 222,000",
                                            "weight": "bolder",
                                            "size": "medium"
                                        },
                                        {
                                            "type": "TextBlock",
                                            "text": "666 MMM St",
                                            "isSubtle": true
                                        },
                                        {
                                            "type": "TextBlock",
                                            "text": "2 beds • 1 baths • 0.138 AC",
                                            "isSubtle": true
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        "facebook": {
            "text": "Here are the listings for 77777"
        }
    },
    "fulfillmentText": "Here are the listings for 77777",
    "outputContexts": []
}

and my config looks like this currently. image

I don't know what to put in the JSON-Path for media? Can I test particular values of columns of an Adaptive Cards or is it only possible to map some of the values to object in Response hook ? Or some regex testing e.g. that column with price contains USD. Do you have any ideas?

ujja commented 5 years ago

A connector creates from a response like your json, a generic BotiumMessage using the Capabilities in response section of your screenshot. In this BotiumMessage can be a card section, but it has no Capability on UI.

But there is a special Capability, the Response hook (see your screenshot). With it you can set all fields of the BotiumMessage (like cards)

Response hook is documented here.

And you can see here the BotiumMessage, with its 'cards' field.

You can use button, and media asserter to check the cards section. (We are planning to create an asserter dedicated to cards section)

piotrjak commented 5 years ago

Thanks for the response. I have some other questions concerning Botium as I feel like i'm getting a little better grasp of it at the moment.

But there is a special Capability, the Response hook (see your screenshot). With it you can set all fields of the BotiumMessage (like cards)

I have this config and you can see the SIMPLE_REST_RESPONSE_HOOK image I don't know how can I set all the fields of the BotiumMessage in there. How can I get the response.payload.attachments.adaptiveCard array (I attached it in the HTTP response image above) and set it in botMsg.cards ? Also, how can I write a function or use ` ` if botium.json config is a json file? you can't use JS functions or ` `\ in there and in the tutorial it's written like you can

SIMPLEREST_RESPONSE_HOOK: `
  botMsg.messageText = botMsg.messageText || 'default message' 
  context.messageSent = botMsg.messageText
`

I'm assuming that CUSTOM CAPABILITY is needed to then use JSONPath like with "SIMPLEREST_RESPONSE_JSONPATH" and extract the cards and then they will be available at botMsg.cards e.g.. I don't think I can use "SIMPLEREST_MEDIA_JSONPATH" as they expect an array of strings and my adaptive cards are objects? (should return an array of strings) image Furthermore, to check particular fields on the adaptive cards I would need to create custom assertion, right? but if I have botMsg.cards on botMsg then it will be easy to write conditions in

{
  assertConvoStep: "if (botMsg.message !== 'hugo') throw 'expected hugo'"
}

So basically BUTTONS and MEDIA assertions are checking whether botMsg.buttons contain the strings that are written in .convo.text file? e.g.

botMsg.buttons = ['one', two']

#bot 
hey
BUTTONS one | two 

All in all, I should probably just write CUSTOM CONNECTOR (with custom CAPABILITIES) and CUSTOM ASSERTIONS to check different parts of the adaptive cards?

piotrjak commented 5 years ago

Oh, ok - I can get the adaptiveCards from context object that I set via SIMPLEREST_CONTEXT_JSONPATH. The questions with using functions in JSON format still stay though. And please confirm whether I understand the whole process correctly.

piotrjak commented 5 years ago

I followed this tutorial to create a custom asserter, but it doesn't work (no console.log and doesn't throw any errors when it should). https://github.com/codeforequity-at/botium-core/tree/master/samples/extensions/logichooks image Am I missing something? I created an Asserter class from template, I wanted to check one property on the card (it isn't xd) and put it to ASSERTERS entry in the botium.json file.

codeforequity-at commented 5 years ago

Hi,

We have a discord channel for Botium developers, would be better place to have this discussion. Please contact us at our website to get invitation link if you want!

codeforequity-at commented 5 years ago

any news ? have you been successful ?

piotrjak commented 5 years ago

Yes, thanks to your help I managed to get it to work! :) I was doing this initial research for the company I work for and they will decide if they want to use your product!

I will contact you to get invitation link to discord as soon as my company decides to use Botium.

codeforequity-at commented 5 years ago

If the structure of the returned JSON is varying, then I think you have to build your own Botium connector (https://botium.atlassian.net/wiki/spaces/BOTIUM/pages/38502401/Writing+own+connector) - to convert the JSON response into something Botium core understands. You can use the existing asserters then, this is what I would recommend here.

Simulation of button clicks is something which highly depends on the implementation details of the chatbot. Some chatbots handle button clicks as text input (and apply intent resolution on it), others are using custom event types (typically Azure MS Bot Framework), for Dialogflow you can do it either way (using postbacks or text queries), ... when you develop your own connector, you can decide yourself how you want button clicks to be handled.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.