Categories:
directline-whatsapp-service plugin
Technical description of directline-whatsapp-service plugin
Introduction
directline-whatsapp-service plugin contains the services and utilities for directline-whatsapp message conversion.
The specific environment variables for this plugin are located at directline-whatsapp-service configuration.
Consumes components (IOC)
| Name | Type | Description |
|---|---|---|
| configurationManager | PluginType.Service | Configuration manager |
| prometheus | PluginType.Service | Metrics client for prometheus |
| whatsappService | PluginType.Service | Services and utilities for WhatsApp channel |
Provides components (IOC)
| Name | Type | Description |
|---|---|---|
| directlineWhatsappService | PluginType.Service | Services and utilities for Direct Line - WhatsApp message conversion |
whatsappService
The DirectlineWhatsappService class provides the following utilities:
-
directlineToWhatsappConverter: It converts DirectLine messages (DirectlineMessageModel) to WhatsApp messages (WhatsappMessageResponseModel). -
directlineWhatsappUtils: Utilities to help with message conversion: DirectLine to WhatsApp.
Converting Direct Line messages to WhatsApp models
The DirectlineToWhatsappConverter class extends from AuraBridgeMessageConverter and converts DirectLine messages to WhatsApp models.
To make this conversion, the DirectlineToWhatsappConverter differences between the following types of messages depending on the DirectLine message content:
| Type | Direct Line message content |
|---|---|
text |
Direct Line messages that do not contain attachments |
list |
Direct Line messages that contain more than one attachment and the attachmentLayout field value is list. |
carousel |
Direct Line messages that contain more than one attachment and the attachmentLayout field value is carousel. |
heroCard |
Direct Line message that contains a single attachment and the contentType field value is application/vnd.microsoft.card.hero. |
file |
Direct Line message that contains a single attachment and the contentType field value is application/vnd.telefonica.aura.file. |
template |
Direct Line message that contains a single attachment and the contentType field value is application/vnd.telefonica.aura.template. |
videoCard |
Direct Line message that contains a single attachment and the contentType field value is application/vnd.microsoft.card.video. |
whatsapp |
Direct Line message that contains a single attachment and the contentType field value is application/vnd.telefonica.aura.whatsapp. |
In the case of list and carousel, in which there is more than one attachment, each attachment in list follows the same procedure to obtain type depending on the value of the contentType field.
⚠️ Currently, the file, template and videoCard types are disabled when they must be generated from list or carousel.
Type text conversion
DirectLine messages identified with the text type is transformed to WhatsApp text messages using the WhatsappMessageFactory.createTextMessage.
Find further information about sending WhatsApp text messages.
Type heroCard conversion
DirectLine messages identified with the heroCard type is transformed to WhatsApp text messages using the WhatsappMessageFactory.createTextMessage.
These messages will be transformed to WhatsApp list messages, WhatsApp reply buttons or enumerated text lists, following the defined guidelines in WhatsApp list options.
The transformation to a WhatsApp message depends on the type of list obtained:
-
buttontype. It will be transformed to WhatsApp interactive button message using theWhatsappMessageFactory.createInteractiveButtonMessage. -
listtype. It will be transformed to WhatsApp interactive list message using theWhatsappMessageFactory.createInteractiveListMessage. -
enumeratedListtype. It will be transformed to WhatsApp formatted text message using theWhatsappMessageFactory.createHeroCardMessage.
Type file conversion
DirectLine messages identified with the file type is transformed to WhatsApp media messages using the WhatsappMessageFactory.createFileMessage.
The currently supported file types are: image, document, audio and video.
Find here further information about sending WhatsApp media messages.
Type template conversion
DirectLine messages identified with the template type is transformed to WhatsApp media messages using the WhatsappMessageFactory.createTemplateMessage.
Find here further information about sending WhatsApp template messages.
Type videoCard conversion
DirectLine messages identified with the template type will be transformed to WhatsApp media messages using the WhatsappMessageFactory.createTemplateMessage.
Find here further information about sending WhatsApp template messages.
Type whatsapp conversion
Direct Line messages identified as type whatsapp will be sent to WhatsApp without any transformation. This kind of
messages is composed of an attachment type application/vnd.telefonica.aura.whatsapp whose content will be sent directly to
WhatsApp. Only the field to will be added.
Text conversion to WhatsApp markdown format
All texts obtained using LocaleManager instance are formatted in WhatsApp markdown format. This implies that all resources defined in POEditor to be used in WhatsApp messages must use the markdown standard format.
The getLocaleTextWithParsedMarkdown function from whatsapp-message-utils is responsible for converting the text to WhatsApp markdown format.
For the text sent from the DirectLine message, the DirectlineToWhatsappConverter class converts text to WhatsApp markdown format according to the following:
- If the DirectLine message contains information in the
channelData.payload.bridge.whatsapp.textConvertfield, its value is used to convert to WhatsApp markdown format. - If the request field is not present, the channel configuration is used.
- Finally, if it is not possible to obtain conversion information in the previous cases, the text message is converted by default.
By default, aura-bridge converts the text received from DirectLine message to specific WhatsApp markdown format.
The practical processes for modifying this behavior is explained in the following documents:
- Configuration to WhatsApp markdown format by channel
- Configuration to WhatsApp markdown format by use case (dialog)