Skip to content

Bot Framework SDK for JavaScript v4.6.0-preview2

Pre-release
Pre-release
Compare
Choose a tag to compare
@stevengum stevengum released this 04 Nov 17:08
d2d81d1

Welcome to the 4.6.0-preview2 release of the Bot Framework SDK for JavaScript available via MyGet!

This is a preview release for streaming support in the Bot Framework SDKs for JavaScript.

Changes:

Breaking Changes:

  • botframework-streaming-extensions and botbuilder-streaming-extensions have been delisted from MyGet
    • botbuilder contains the updated BotFrameworkAdapter class which is used to interpret incoming streaming requests (formerly botbuilder-streaming-extensions and BotFrameworkStreamingAdapter)
    • botframework-streaming now contains the Request and Transport layer specific code (formerly botframework-streaming-extensions)

Changes:

  • Developers must set enableWebSockets to true in BotFrameworkAdapterSettings to enable WebSockets
  • BotFrameworkAdapter now uses a Factory pattern for more extensibility when using WebSockets
    • Developers can pass in an instance of a NodeWebSocketFactoryBase to the BotFrameworkAdapter via BotFrameworkAdapterSettings.webSocketFactory
    • If enableWebSockets is true and no factory is passed in, the BotFrameworkAdapter will default to a NodeWebSocketFactory
  • BotFrameworkAdapter.useWebSocket() and BotFrameworkAdapter.useNamedPipe() are now public
  • Fixed filename casing issues
  • Minor cleanup and bug fixes

Samples:

For an example of how to configure your bot to use WebSockets and Direct Line Speech, please visit the botbuilder-samples repository. Navigate to the /experimental/directline-speech/javascript_nodejs/02.echo-bot sample which was updated via this commit: microsoft/BotBuilder-Samples@651f405

Here is a modified snippet from the sample which shows how to set configure a bot to use WebSockets:

// Create HTTP server and configure the Server to handle for Upgrade requests.
const server = restify.createServer({ handleUpgrades: true });
server.listen(process.env.port || process.env.PORT || 3978);

// BotFrameworkAdapterSettings configuration object.
const adapterSettings = {
    appId: process.env.MicrosoftAppId,
    appPassword: process.env.MicrosoftAppPassword
};

const myBot = new EchoBot();

// Listen for GET requests to the same route to accept Upgrade requests for Streaming.
server.get('/api/messages', (req, res) => {
    // Create an adapter scoped to this WebSocket connection to allow storing session data.
    // Get the appId and appPassword from the above settings object and set enableWebSockets to true.
    const streamingAdapter = new BotFrameworkAdapter({
        ...adapterSettings,
        enableWebSockets: true
    });
    // Set onTurnError for the BotFrameworkAdapter created for each connection.
    streamingAdapter.onTurnError = onTurnErrorHandler;

    streamingAdapter.processActivity(req, res, async (context) => {
        // After connecting via WebSocket, run this logic for every request sent over
        // the WebSocket connection.
        await myBot.run(context);
    });
});