1.2.14 • Published 6 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
6 years ago
1.2.13
6 years ago
1.2.12
6 years ago
1.2.11
6 years ago
1.2.10
6 years ago
1.2.9
6 years ago
1.2.8
6 years ago
1.2.7
6 years ago
1.2.6
6 years ago
1.2.5
6 years ago
1.2.4
6 years ago
1.2.3
6 years ago
1.2.2
6 years ago
1.2.1
6 years ago
1.2.0
6 years ago
1.1.4
6 years ago
1.1.3
6 years ago
1.1.2
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.17
6 years ago
1.0.16
6 years ago
1.0.15
6 years ago
1.0.14
6 years ago
1.0.13
6 years ago
1.0.12
6 years ago
1.0.11
6 years ago
1.0.10
6 years ago
1.0.9
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago