1.2.14 • Published 5 years ago
botbuilder-adapter v1.2.14
botbuilder-adapter
Features
- Better Error handling
- Easier Testing
- Simpler Api
Usage
Install the necessary dependencies:
npm install botbuilder-adapter botbuilder botbuilder-dialogs restify typescript source-map-support &&
npm install --save-dev nodemon @types/source-map-support ts-node
Create a bot:
// bot.ts
import { ActivityHandler, TurnContext } from 'botbuilder'
import { createAdapter } from 'botbuilder-adapter'
async function sendCactus(context: TurnContext): Promise<void> {
await context.sendActivity('🌵')
}
/**
* Creates a bot that just sends 🌵.
*/
export function createCactusBot(): ActivityHandler {
const adapter = createAdapter()
adapter.onMembersAdded = sendCactus
adapter.onMessage = sendCactus
return adapter.bot
}
Create a server:
// server.ts
import 'source-map-support/register'
import * as restify from 'restify'
import { BotFrameworkAdapter } from 'botbuilder'
import { createCactusBot } from './bot'
// Create adapter.
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
})
// Create the bot.
const myBot = createCactusBot()
// Create HTTP server.
const server = restify.createServer()
// Listen for incoming requests.
server.post('/api/messages', (req: any, res: any) => {
adapter.processActivity(req, res, async context => {
// Route to main dialog.
await myBot.run(context)
})
})
const port = process.env.port || process.env.PORT || 3978
server.listen(port, () => {
console.log(`🌵 listening to http://localhost:${port}/api/messages`)
})
Run it:
npx nodemon --exec ts-node server.ts
1.2.14
5 years ago
1.2.13
5 years ago
1.2.12
5 years ago
1.2.11
5 years ago
1.2.10
5 years ago
1.2.9
5 years ago
1.2.8
5 years ago
1.2.7
5 years ago
1.2.6
5 years ago
1.2.5
5 years ago
1.2.4
5 years ago
1.2.3
5 years ago
1.2.2
5 years ago
1.2.1
5 years ago
1.2.0
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.17
5 years ago
1.0.16
5 years ago
1.0.15
5 years ago
1.0.14
5 years ago
1.0.13
5 years ago
1.0.12
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago