Categories:
Aura channelData utils
channelData utils Aura utils is an utility found in Aura Bot common library in charge of managing Aura Bot channelData
Introduction
channelData utils utility allows managing Aura channelData.
Find more information in the Github repository: https://github.com/Telefonica/aura-common-utilities/tree/master/packages/aura-bot-utilities/src/aura-bot-common/utils
It contains different methods, described in the following sections.
getAuraModality
It returns the modality associated to a context. Otherwise, it returns an error if the channel could not be retrieved and injected into the message.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Types of AuraModality:
export enum AuraModality {
text = 'text',
voice = 'voice',
form = 'form'
}
Example of use:
const modality = ChannelDataUtils.getAuraModality(context);
getFullAura
It returns fullAura object from auraMode.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const fullAura = ChannelDataUtils.getFullAura(context);
getAppContext
It gets AppContext from client and returns an structure with certain information about the client such as: device, application, location, channel, etc.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const appContext = ChannelDataUtils.getAppContext(context);
getCustomContent
It returns a boolean if it is a custom content.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const isCustomContent: boolean = ChannelDataUtils.getCustomContent(context);
getAuraId
It gets Aura id from the activiy.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
| channelsConfig | AuraChannelsConfiguration | Channels configuration to obtain channelUserSeparator in case the function needs it |
no |
Example of use:
const auraId: string = ChannelDataUtils.getAuraId(context);
getAuraCommandIntent
It gets the auraCommand intent.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const auraCommandIntent: string = ChannelDataUtils.getAuraCommandIntent(context);
getChannelConfiguration
It gets the complete channel configuration from id or name.
| param | type | description | mandatory |
|---|---|---|---|
| channelsConfiguration | AuraChannelsConfiguration | Channels configuration. | yes |
| channelId | string | Channel identifier. | yes |
| channelName | string | Channel name. | yes |
Example of use:
const channel: ChannelConfiguration = ChannelDataUtils.getChannelConfiguration(channelsConfiguration, channelId, channelName);
getChannelId
It gets the channel Id.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const channelId: string = ChannelDataUtils.getChannelId(context);
getChannelName
It gets the channel name.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const channelName: string = ChannelDataUtils.getChannelName(context);
getChannelPrefix
It gets the channel prefix.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const channelPrefix: string = ChannelDataUtils.getChannelPrefix(context);
getDeviceId
It gets the device Id.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const deviceId: string = ChannelDataUtils.getDeviceId(context);
getAccountNumber
It gets the account number from userContext.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const accountNumber: string = ChannelDataUtils.getAccountNumber(context);
getRequestVersion
It returns the channelData version. If it is not found, AURA_CHANNELDATA_DEFAULT_VERSION will be returned.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
Example of use:
const version: string = ChannelDataUtils.getRequestVersion(context);
setAppContext
It sets AppContext in channelData. In certain scenarios, it will be necessary to overwrite it to keep the track of changes that have occurred (e.g., in the applied contextFilters).
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
| appContext | any | New appContext to overwrite | yes |
Example of use:
ChannelDataUtils.setAppContext(context, appContext);
getActions
It gets actions from channelData. If exists, target will only extract actions for this target.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
| target | string | Optional parameter to filter the actions by target | no |
Example of use:
const actions = ChannelDataUtils.getActions(context);
getStatusFromMessage
It gets status to message activity.channelData.status.
| param | type | description | mandatory |
|---|---|---|---|
| activity | Partial |
Activity. | yes |
Example of use:
const status: AuraResponseStatus = ChannelDataUtils.getStatusFromMessage(activity): ;
getPayloadEvent
It gets the payload event.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from. | yes |
Example of use:
const payload: ChannelDataPayload.PayloadEvent = ChannelDataUtils.getPayloadEvent(context);
getPayloadAsyncCallback
It gets the payload asyncCallback.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from. | yes |
Example of use:
const payload = ChannelDataUtils.getPayloadAsyncCallback(context);
getPayloadBridgeUser
It gets the bridge user.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from. | yes |
Example of use:
const payload: ChannelDataPayload.PayloadEvent = ChannelDataUtils.getPayloadBridgeUser(context);
Methods to be used only by Aura Bot
setAuraCommad
It sets an auraCommand, adding to the channelData attribute the auraCommand object with the type and value attributes.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
| auraCommand | AuraCommand | AuraCommand to be set | yes |
Example of use:
ChannelDataUtils.setAuraCommad(this.context, new AuraCommand(AuraCommandType.TYPE, commandValue))
setResponseVersion
It sets the channelData version.
| param | type | description | mandatory |
|---|---|---|---|
| target | TurnContext | Partial |
|
| configuration | Configuration | Set of of configuration variables. | yes |
| version | string | Version to be set | no |
Example of use:
const currentResponseVersion: string = ChannelDataUtils.setResponseVersion(activity, ConfigurationManager.instance.environmentConfiguration);
checkRequestVersion
It determines whether the version is major than AURA_RESPONSE_VERSION or not.
| param | type | description | mandatory |
|---|---|---|---|
| context | TurnContext | Context where the channel data will be taken from | yes |
| configuration | Configuration | Set of configuration variables. | yes |
Example of use:
const check: boolean = ChannelDataUtils.checkRequestVersion(context, ConfigurationManager.instance.environmentConfiguration);
setStatusToMessage
It sets status to message activity.channelData.status.
| param | type | description | mandatory |
|---|---|---|---|
| activity | Partial |
Activity | yes |
| status | status | status to set | yes |
Example of use:
ChannelDataUtils.setStatusToMessage(activity, status): ;