← Botkit Documentation ← Class Index
This is a class reference for all the methods exposed by the botbuilder-adapter-web package.
Connect Botkit or BotBuilder to the Web. It offers both websocket and webhook capabilities. To use this adapter, you will need a compatible chat client - generate one using the Botkit yeoman generator, or use the one included in the project repo here.
To use this class in your application, first install the package:
npm install --save botbuilder-adapter-web
Then import this and other classes into your code:
const { WebAdapter } = require('botbuilder-adapter-web');
This class includes the following methods:
- continueConversation()
- createSocketServer()
- getConnection()
- init()
- isConnected()
- processActivity()
- sendActivities()
Parameters
Argument | Type | Description |
---|---|---|
socketServerOptions | an optional object containing parameters to send to a call to WebSocket.server. |
Create an adapter to handle incoming messages from a websocket and/or webhook and translate them into a standard format for processing by your bot.
To use with Botkit:
const adapter = new WebAdapter();
const controller = new Botkit({
adapter: adapter,
// other options
});
To use with BotBuilder:
const adapter = new WebAdapter();
const server = restify.createServer();
server.use(restify.plugins.bodyParser());
// instead of binding processActivity to the incoming request, pass in turn handler logic to createSocketServer
let options = {}; // socket server configuration options
adapter.createSocketServer(server, options, async(context) => {
// handle turn here
});
Name | Type | Description |
---|---|---|
wss | any | The websocket server. |
Standard BotBuilder adapter method for continuing an existing conversation based on a conversation reference. BotBuilder reference docs
Parameters
Argument | Type | description |
---|---|---|
reference | Partial<ConversationReference> | A conversation reference to be applied to future messages. |
logic | A bot logic function that will perform continuing action in the form async(context) => { ... } |
Bind a websocket listener to an existing webserver object. Note: Create the server using Node's http.createServer
Parameters
Argument | Type | description |
---|---|---|
server | any | an http server |
socketOptions | any | additional options passed when creating the websocket server with WebSocket.server |
logic | any | a turn handler function in the form async(context)=>{ ... } that will handle the bot's logic. |
Returns websocket connection of given user
Example: if (message.action === 'disconnect') bot.controller.adapter.getConnection(message.user).terminate()
Parameters
Argument | Type | description |
---|---|---|
user | string |
Botkit-only: Initialization function called automatically when used with Botkit. * Calls createSocketServer to bind a websocket listener to Botkit's pre-existing webserver.
Parameters
Argument | Type | description |
---|---|---|
botkit | any |
Is given user currently connected? Use this to test the websocket connection between the bot and a given user before sending messages, particularly in cases where a long period of time may have passed.
Parameters
Argument | Type | description |
---|---|---|
user | string | the id of a user, typically from message.user |
Example: bot.controller.adapter.isConnected(message.user)
Accept an incoming webhook request and convert it into a TurnContext which can be processed by the bot's logic.
Parameters
Argument | Type | description |
---|---|---|
req | any | A request object from Restify or Express |
res | any | A response object from Restify or Express |
logic | A bot logic function in the form async(context) => { ... } |
Standard BotBuilder adapter method to send a message from the bot to the messaging API. BotBuilder reference docs.
Parameters
Argument | Type | description |
---|---|---|
context | TurnContext | A TurnContext representing the current incoming message and environment. (not used) |
activities | An array of outgoing activities to be sent back to the messaging API. |