-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteamsBot.ts
46 lines (39 loc) · 1.16 KB
/
teamsBot.ts
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
import {
ActivityTypes,
CardFactory,
TeamsActivityHandler,
TurnContext,
} from "botbuilder";
import { api } from "../api";
import { cardBody } from "../components/cardBody";
export class TeamsBot extends TeamsActivityHandler {
constructor() {
super();
this.onMessage(async (context, next) => {
const removedMentionText = TurnContext.removeRecipientMention(
context.activity,
);
const txt = removedMentionText.toLowerCase().replace(/\n|\r/g, "").trim();
await context.sendActivity({ type: ActivityTypes.Typing });
try {
const response = await api.answer(txt);
console.log(response);
await context.sendActivity({
type: ActivityTypes.Message,
attachments: [
CardFactory.adaptiveCard({
type: "AdaptiveCard",
body: cardBody(response),
}),
],
});
// By calling next() you ensure that the next BotHandler is run.
await next();
} catch (error) {
console.error(error);
await context.sendActivity("Sorry, I missed that. Please try again.");
await next();
}
});
}
}