Dispatch attachment based on channel condition

Hi @nik20, I have a custom action which creates a carousel in rasa webchat as shown and it is running properly with bot connected to a socket channel as well as a botframework channel for Microsoft Teams chatbot integration.

carousel = {
            "type": "template",
            "payload": 
                {
                "template_type": "generic",
                "elements": [
                    {
                        "title": "Select one:",
                        "buttons": [ 
                            {
                            "title": "Get ticket status",
                            "payload": "/show_ticketstatus",
                            "type": "postback"
                            },
                            {
                            "title": "SLAs about to breach",
                            "payload": "/bot_initialization_SLA",
                            "type": "postback"
                            },
                            {
                            "title": "Tickets assigned to me",
                            "payload": "/ticket_assigned",
                            "type": "postback"
                            },
                            {
                            "title": "Don't do anything",
                            "payload": "/deny",
                            "type": "postback"
                            }
                        ]
                    },
                ]
                }
        }
        dispatcher.utter_message(response="utter_action_greet_ITSM",attachment=carousel)

Output -

Now, after interating it with MS Teams, in Teams this carousel section shows up as JSON data instead of showing up as a carousel. I don’t want that to happen. What I want is that -

dispatcher.utter_message(response="utter_action_greet_ITSM",attachment=carousel)

This above line of code should be displayed only when the channel is socketio. I also checked out this documentation, but it is only useful for uttering reponses which have either texts or buttons, but not attachments of this sort. Please help me out with this.

@Horizon733 , buddy if you could also check this out and help me out then it would mean a lot to me. Thanks!

@webdev-rohit

Thanks for tagging me, I can see you tag me with @ nik20 but sorry, it’s not my alias :wink: but still no worries.

The code you shared is used for Card carousels features and it’s working fine, as per this

there is no detail or screenshot?

Secondly, this is the only known solution for channel-specific, did you try with texts or buttons?

Share some more screenshots related to your issue and personally, I have not implemented this use case with other channels, but I will try my best to help you.

Good Luck!

Hi again @nik202 ! Sorry for the wrong tag first of all.

Coming to the screenshot you had asked for in Teams-

Now, as you see here, the attachment is being displayed as json. So, I thought of passing this attachment only for the socket channel and not the Teams channel since in the socket channel, the json is properly showing up as a carousel attachment as needed.

So, I just want to know how to put a channel condition on attachments. As referred in my previous post in this thread, Rasa has provided documentation for channel specific responses, but it covers only buttons and texts and not about attachments or json data like this. I need help with this. Thanks in advance!

@webdev-rohit check the documentation on MS Team, that they offer the card feature or button feature? or have you seen it anywhere else, please do share me?

May be this will give you better idea: Types of cards - Teams | Microsoft Docs

Good Luck!

@nik202 thank you for the provided link. I’ll check and let you know.

@webdev-rohit do remember to tag me, good luck!

Sure @nik202

Hi @nik202 , I’m able to create and see cards in Teams chat and also differentiate it from my socket channel responses. I’ll attach the info in some time. However, for now I need your help/suggestions with another piece of blocker I’ve come across. I’ll create a post for it and tag you there.

@webdev-rohit Sure, no worries, please close this thread as a solution for others.

The trick is to use tracker.get_latest_input_channel() and use if else condition. Example -

channelName = tracker.get_latest_input_channel() print(channelName) if channelName == ‘socketio’: print(tracker.latest_message[‘metadata’]) userName = tracker.latest_message[‘metadata’][‘userId’] print(userName) dispatcher.utter_message(response=“utter_action_greet_ITSM”,username=userName,attachment=carousel) elif channelName == ‘botframework’: # print(tracker.current_state()) print(tracker.latest_message[‘metadata’]) userName = tracker.latest_message[‘metadata’][‘name’]
print(userName) dispatcher.utter_message(response=“utter_action_greet_ITSM”,username=userName,buttons=[ {“title”: “Get ticket status”, “payload”: “/show_ticketstatus”, “type”: “messageBack”, “text”: “/show_ticketstatus”, “displayText”: “Get ticket status”}, {“title”: “SLAs about to breach”, “payload”: “/bot_initialization_SLA”, “type”: “messageBack”, “text”: “/bot_initialization_SLA”, “displayText”: “SLAs about to breach”}, {“title”: “Tickets assigned to me”, “payload”: “/ticket_assigned”, “type”: “messageBack”, “text”: “/ticket_assigned”, “displayText”: “Tickets assigned to me”}, {“title”: “Don’t do anything”, “payload”: “/deny”, “type”: “messageBack”, “text”: “/deny”, “displayText”: “Don’t do anything”} ])