Handling user messages in RCS channel

The current document includes the guidelines for handling different types of messages in the RSC channel.

Handling user button responses

Some messages received from RCS channels have a particular behavior and some data is returned to the dialog in a new field of the channelData: channelData.payload.suggestionResponse.

Here is an example of a user response of this type:

{
    "type": "message",
    "id": "d152aee9-1aaa-5b54-95a5-79352eee2e45|MxRCKxirowTtaiNb8-REy9TA",
    "channelId": "f7fd1021-41cd-588a-a461-387cc24be225",
    "from": {
        "id": "34659949469",
        "name": "javiagent_crbwyhqz_agent@rbm.goog"
    },
    "conversation": {
        "id": "c0709653-45f7-4fca-9808-3702d11fc346"
    },
    "channelData": {
        "payload": {
            "suggestionResponse": {
                "postbackData": "{\\"intent\\": \\"intent.factotum-test.rcs-formats\\",\\"entities\\":[{\\"type\\":\\"type\\",\\"entity\\":\\"postback\\"},{\\"type\\":\\"data\\",\\"entity\\":\\"card 1\\"}]}",
                "text": "Card #1",
                "type": "REPLY"
            },
            "bridge": {
                "channelId": "f7fd1021-41cd-588a-a461-387cc24be225"
            },
            "auraGroot": {
                "channelConversationId": "d152aee9-1aaa-5b54-95a5-79352eee2e45",
                "channelId": "f7fd1021-41cd-588a-a461-387cc24be225"
            }
        },
        "version": "3",
        "appContext": {
            "channel": {
                "modality": "text",
                "id": "f7fd1021-41cd-588a-a461-387cc24be225"
            },
            "timestamp": "2024-10-04T16:36:55+02:00",
            "timezone": "Europe/Madrid"
        },
        "correlator": "1be1b360-8cc4-4a4d-845b-bebb47869afd"
    },
    "text": "{\\"intent\\": \\"intent.factotum-test.rcs-formats\\",\\"entities\\":[{\\"type\\":\\"type\\",\\"entity\\":\\"postback\\"},{\\"type\\":\\"data\\",\\"entity\\":\\"card 1\\"}]}",
    "serviceUrl": "http://localhost:8080/api/skills",
    "relatesTo": {
        "serviceUrl": "http://localhost:8045/aura-services/javiagent",
        "activityId": "d152aee9-1aaa-5b54-95a5-79352eee2e45|MxRCKxirowTtaiNb8-REy9TA",
        "channelId": "f7fd1021-41cd-588a-a461-387cc24be225",
        "conversation": {
            "id": "d152aee9-1aaa-5b54-95a5-79352eee2e45"
        },
        "bot": null
    },
    "recipient": {
        "role": "skill"
    },
    "callerId": "urn:botframework:aadappid:3837ac07-50e0-4d4e-993b-1bda1349f25a",
    "locale": "es-cr"
}

The value of text and postbackData was set by the dialog when the card was sent, you can find more info in building Aura response

Handling suggestion responses

Buttons in cards, prompts or suggestions, return a REPLY response as the following suggestionResponse:

"suggestionResponse": {
    "postbackData": "Rock",
    "text": "Rock",
    "type": "REPLY"
}

If prompts are created as specified in building Aura response, they will be handled properly without any extra steps, because postbackData will be the text field of the activity and will be recognized by the prompt as an option.

Handling actions responses

Actions return an ACTION response as the following ones:

"suggestionResponse": {
    "postbackData": "{\\"intent\\": \\"intent.factotum-test.rcs-formats\\",\\"entities\\":[{\\"type\\":\\"type\\",\\"entity\\":\\"postback\\"},{\\"type\\":\\"data\\",\\"entity\\":\\"la ubicación\\"}]}",
    "text": "View map",
    "type": "ACTION"
}
"suggestionResponse": {
    "postbackData": "{\\"intent\\": \\"intent.factotum-test.rcs-formats\\",\\"entities\\":[{\\"type\\":\\"type\\",\\"entity\\":\\"postback\\"},{\\"type\\":\\"data\\",\\"entity\\":\\"llamar\\"}]}",
    "text": "Call",
    "type": "ACTION"
}

Ignoring responses

Every button sent to the user must have the postbackData field included:

            'contentMessage': {
                'text': 'Call technical service',
                'suggestions': [
                    {
                        'action': {
                            'text': 'Call us!',
                            'postbackData': '{"intent": "intent.factotum-test.rcs-formats","entities":[{"type":"type","entity":"postback"},{"type":"data","entity":"call"}]}',
                            'fallbackUrl': 'https://www.google.com/contact/',
                            'dialAction': {
                                'phoneNumber': '+66666666666'
                            }
                        }
                    }
                ]
            }

And this postbackData will be returned as a message to aura-bot when the user clicks the button. If you want to ignore this message or only write a log, you should implement a specific dialog to handle these actions and send every action response to this dialog with an aura-command:

{
                    contentType: 'application/vnd.telefonica.aura.rcs.message', content: {
                        'contentMessage': {
                            'text': 'Location message',
                            'suggestions': [
                                {
                                    'action': {
                                        'text': 'View map',
                                        'postbackData': '{"intent": "intent.ignore-user-postback.example-dialog","entities":[]}',
                                        'fallbackUrl': 'https://www.google.com/maps/place/40%C2%B021\'39.5%22N+4%C2%B020\'01.8%22W/@40.3609722,-4.3338333,17z',
                                        'viewLocationAction': {
                                            'latLong': {
                                                'latitude': '40.36085110',
                                                'longitude': '-4.33394257'
                                            },
                                            'label': 'Pelayos de la presa, pedacito de cielo'
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }