-
Notifications
You must be signed in to change notification settings - Fork 710
/
bot.js
56 lines (47 loc) · 1.9 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import {
TeamsActivityHandler,
BotFrameworkAdapter,
MemoryStorage,
ConversationState,
TurnContext,
} from 'botbuilder';
import config from 'config';
// Create adapter.
// See https://aka.ms/about-bot-adapter to learn more about adapters.
export const adapter = new BotFrameworkAdapter({
appId: config.get('bot.appId'),
appPassword: config.get('bot.appPassword'),
});
adapter.onTurnError = async (context, error) => {
const errorMsg = error.message
? error.message
: `Oops. Something went wrong!`;
// This check writes out errors to console log .vs. app insights.
// NOTE: In production environment, you should consider logging this to Azure
// application insights.
console.error(`\n [onTurnError] unhandled error: ${error}`);
// Clear out state
await conversationState.delete(context);
// Send a message to the user
await context.sendActivity(errorMsg);
// Note: Since this Messaging Extension does not have the messageTeamMembers permission
// in the manifest, the bot will not be allowed to message users.
// Uncomment below commented line for local debugging.
// await context.sendActivity(`Sorry, it looks like something went wrong. Exception Caught: ${errorMsg}`);
};
// Define state store for your bot.
const memoryStorage = new MemoryStorage();
// Create conversation state with in-memory storage provider.
const conversationState = new ConversationState(memoryStorage);
export class EchoBot extends TeamsActivityHandler {
constructor() {
super();
this.onMessage(async (context, next) => {
TurnContext.removeRecipientMention(context.activity);
const text = context.activity.text.trim().toLocaleLowerCase();
await context.sendActivity('You said ' + text);
});
}
}