Categories:
Aura Bot ADapter
Description of aura-bot-adapter component, that extends the CloudAdapter class, the new implementation offered by Microsoft Bot Framework, which implements the Bot Framework Protocol and substitutes the deprecated BotFrameworkAdapter
Introduction
CloudAdapter is the new implementation offered by Microsoft Bot Framework, which implements the Bot Framework Protocol and substitutes the deprecated BotFrameworkAdapter class (deprecated since version 4.16.0).
The aura-bot component aura-bot-adapter now extends the CloudAdapter class and applies new methods to facilitate deployments on cloud’s environments.
aura-bot-adapter has the following roles:
- It overwrites the
sendActivitiesmethod of its parent to provide the feature of having all the activities returned in a turn in a single queue, so they can be handled properly by the batch-outgoing-message-middleware.
Implementation
The main changes that have been implemented during CloudAdapter modification are explained in the following sections:
Initialization
In CloudAdapter, there are differences on how to initialize the adapter. Configuration authentication variables are divided into ConfigurationServiceClientCredentialFactory and ConfigurationBotFrameworkAuthenticationOptions.
BotFrameworkAdapter (deprecated)
const adapter = new AuraBotAdapter({
appId: this.configuration.AURA_MICROSOFT_APP_ID,
appPassword: this.configuration.AURA_MICROSOFT_APP_PASSWORD,
channelService: this.configuration.AURA_MICROSOFT_CHANNEL_SERVICE,
openIdMetadata: this.configuration.AURA_MICROSOFT_OPEN_ID_METADATA,
authConfig
});
CloudAdapter
const credentialsFactory: ConfigurationServiceClientCredentialFactory = new ConfigurationServiceClientCredentialFactory({
MicrosoftAppId: this.configuration.AURA_MICROSOFT_APP_ID,
MicrosoftAppPassword: this.configuration.AURA_MICROSOFT_APP_PASSWORD
});
const botFrameworkAuthConfig: ConfigurationBotFrameworkAuthenticationOptions = {
ChannelService: this.configuration.AURA_MICROSOFT_CHANNEL_SERVICE,
BotOpenIdMetadata: this.configuration.AURA_MICROSOFT_OPEN_ID_METADATA
};
const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication(botFrameworkAuthConfig, credentialsFactory, authConfig);
const adapter = new CloudAdapter(botFrameworkAuthentication);
processActivity vs process
The CloudAdapter class introduces a new method which processes the incoming request and applies a logic afterwards.
In aura-bot platform, this logic is focused on forwarding incoming petitions to the ActivityHandler.
BotFrameworkAdapter (deprecated)
await adapter.processActivity(req, res, async (context: TurnContext) => {});
CloudAdapter
await adapter.process(req, res, async (context: TurnContext) => {});