Categories:
Building Aura response in RCS channel
Building Aura response for a use case in the RCS channel has certain particularities due to the limitations of this channel
Introduction
When developing a use case, you should follow the general guidelines for building Aura response, which are common for all channels.
However, for RCS channel, certain specific steps must be carried out regarding rendering limitation of this channel and the configuration of the necessary attachments.
Sending messages to clients
Due to the special format of RCS messages and to avoid the extra complexity and maintainability of a transformation in aura-bridge between Directline messages and RCS messages, a new attachment type has been defined to send directly the payload of RCS messages in the activity. This payload will be sent directly to RCS by aura-bridge without any transformation.
Furthermore, the communication between aura-bridge and aura-bot is done using channelData V3, so dialogs should be implemented following the indications in the document Guidelines for creating/migrating a dialog to channelData v3.
Sending a text message
To send a simple text message, send an activity as shown below:
const dialogSettings = DialogUtils.getDataActiveDialog(stepContext, 'options');
const intentResult = dialogSettings?.intentResult;
await stepContext.context.sendActivity({
text: 'Text doesn\'t matter',
channelData: ChannelDataResponseMapper.formatChannelDataV3(intentResult, corr),
attachments: [{
contentType: 'application/vnd.telefonica.aura.rcs.message', content: {
'contentMessage': {
'text': 'Hello, world!'
}
}
}]
});
In the previous example, the text “Hello, world!” will be sent to te user. The text inside the activity’s text field will be ignored.
There is only one special case when the text field of the activity is used to create the message: when the attachment with type application/vnd.telefonica.aura.rcs.message does not exist in a message of an RCS channel. But this case is reserved for error messages or other special situations. By default, text messages should be created with the necessary attachment.
Sending actions
You can send multiple types of actions to the user. All are defined in RCS Documentation.
All these actions have the field postbackData that will be returned to the bot as a text message when the user interacts and the dialog should know how to handle it.
You can set postbackData as a text auraCommand to handle it in a different dialog.
More info in Handling user messages in RCS channel
Sending a dial action
await stepContext.context.sendActivity({
text: 'Text doesn\'t matter',
channelData: ChannelDataResponseMapper.formatChannelDataV3(intentResult, corr),
attachments: [{
contentType: 'application/vnd.telefonica.aura.rcs.message', content: {
'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'
}
}
}
]
}
}
}]
});
Sending a location action
await stepContext.context.sendActivity({
text: 'Text doesn\'t matter',
channelData: ChannelDataResponseMapper.formatChannelDataV3(intentResult, corr),
attachments: [{
contentType: 'application/vnd.telefonica.aura.rcs.message', content: {
'contentMessage': {
'text': 'Location message',
'suggestions': [
{
'action': {
'text': 'View map',
'postbackData': '{"intent": "intent.factotum-test.rcs-formats","entities":[{"type":"type","entity":"postback"},{"type":"data","entity":"location"}]}',
'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'
}
}
}
]
}
}
}]
});
Sending an URL
await stepContext.context.sendActivity({
text: 'Text doesn\'t matter',
channelData: ChannelDataResponseMapper.formatChannelDataV3(intentResult, corr),
attachments: [{
contentType: 'application/vnd.telefonica.aura.rcs.message', content: {
'contentMessage': {
'text': 'Url message',
'suggestions': [
{
'action': {
'text': 'Open Google',
'postbackData': '{"intent": "intent.factotum-test.rcs-formats","entities":[{"type":"type","entity":"postback"},{"type":"data","entity":"el link"}]}',
'openUrlAction': {
'url': 'https://www.google.com'
}
}
}
]
}
}
}]
});
Sending a prompt
Here is an example of how to send a prompt to the user in RCS.
Due to the characteristics of this channel, you need to define the prompt options twice: as choices of the prompt and as suggestion buttons for the user.
As you can see, the choices values are set in choices and also
as suggestions in the attachment. The value in the postbackData must be the same as the one set in the choices, because it will be the value
returned when the button is clicked. The text field of the reply object is the text showed to the user and can have any value.
const dialogSettings = DialogUtils.getDataActiveDialog(stepContext, 'options');
const intentResult = dialogSettings?.intentResult;
const choicesText: Choice[] = [
{ value: 'Accept', synonyms: ['ok', 'yes'] },
{ value: 'Deny', synonyms: ['no'] }];
const promptOptions: PromptOptions = {
prompt: {
text: 'Text doesn\'t matter',
channelData: ChannelDataResponseMapper.formatChannelDataV3(intentResult, corr),
attachments: [{
contentType: 'application/vnd.telefonica.aura.rcs.message', content: {
'contentMessage': {
'text': 'Hello, write one option or write the associated number',
'suggestions': []
}
}
}]
},
choices: ChoiceFactory.toChoices(choicesText)
};
choicesText.forEach((choice, index) => {
(promptOptions.prompt as Partial<Activity>).attachments[0].content.contentMessage.suggestions.push(
{
'reply': {
'text': choice.value,
'postbackData': choice.value
}
});
});
return await stepContext.prompt(this.promptsNames.COMMAND_CHOICE_PROMPT, promptOptions);
Sending rich cards
Rich cards allows you to send more complex messages to the user. All the info about rich cards in RCS can be found here
await stepContext.context.sendActivity({
text: 'Text doesn\'t matter',
channelData: ChannelDataResponseMapper.formatChannelDataV3(intentResult, corr),
attachments: [{
contentType: 'application/vnd.telefonica.aura.rcs.message', content: {
'contentMessage': {
'richCard': {
'standaloneCard': {
'thumbnailImageAlignment': 'RIGHT',
'cardOrientation': 'VERTICAL',
'cardContent': {
'title': 'Hello, world!',
'description': 'RBM is awesome!',
'media': {
'height': 'TALL',
'contentInfo': {
'fileUrl': 'http://www.google.com/logos/doodles/2015/googles-new-logo-5078286822539264.3-hp2x.gif',
'forceRefresh': 'false'
}
},
'suggestions': [
{
'reply': {
'text': 'Suggestion #1',
'postbackData': '{"intent": "intent.factotum-test.rcs-formats","entities":[{"type":"type","entity":"postback"},{"type":"data","entity":"suggestion 1"}]}',
}
},
{
'reply': {
'text': 'Suggestion #2',
'postbackData': '{"intent": "intent.factotum-test.rcs-formats","entities":[{"type":"type","entity":"postback"},{"type":"data","entity":"suggestion 2"}]}',
}
}
]
}
}
}
}
}
}]
});
Sending carousels
Carousels are a special type of rich cards. You can find more info here
await stepContext.context.sendActivity({
text: 'Text doesn\'t matter',
channelData: ChannelDataResponseMapper.formatChannelDataV3(intentResult, corr),
attachments: [{
contentType: 'application/vnd.telefonica.aura.rcs.message', content: {
'contentMessage': {
'richCard': {
'carouselCard': {
'cardWidth': 'MEDIUM',
'cardContents': [
{
'title': 'Card #1',
'description': 'The description for card #1',
'suggestions': [
{
'reply': {
'text': 'Card #1',
'postbackData': '{"intent": "intent.factotum-test.rcs-formats","entities":[{"type":"type","entity":"postback"},{"type":"data","entity":"card 1"}]}',
}
}
],
'media': {
'height': 'MEDIUM',
'contentInfo': {
'fileUrl': 'https://storage.googleapis.com/kitchen-sink-sample-images/cute-dog.jpg',
'forceRefresh': 'false'
}
}
},
{
'title': 'Card #2',
'description': 'The description for card #2',
'suggestions': [
{
'reply': {
'text': 'Card #2',
'postbackData': '{"intent": "intent.factotum-test.rcs-formats","entities":[{"type":"type","entity":"postback"},{"type":"data","entity":"card 2"}]}',
}
}
],
'media': {
'height': 'MEDIUM',
'contentInfo': {
'fileUrl': 'https://storage.googleapis.com/kitchen-sink-sample-images/elephant.jpg',
'forceRefresh': 'false'
}
}
}
]
}
}
}
}
}]
});