-
Notifications
You must be signed in to change notification settings - Fork 839
/
Copy pathteamsBot.js
103 lines (94 loc) · 3.03 KB
/
teamsBot.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { TeamsActivityHandler, CardFactory } = require("botbuilder");
const fs = require('fs');
/**
* TeamsBot class extends TeamsActivityHandler to handle bot activities.
*/
class TeamsBot extends TeamsActivityHandler {
constructor() {
super();
this.onMembersAdded(this.handleMembersAdded.bind(this));
this.onMessage(this.handleMessage.bind(this));
}
/**
* Handles the event when new members are added to the conversation.
* @param {TurnContext} context - The context object for the turn.
* @param {Function} next - The next middleware handler to call.
*/
async handleMembersAdded(context, next) {
const imagePath = 'Images/configbutton.png';
const imageBase64 = fs.readFileSync(imagePath, 'base64');
const card = CardFactory.adaptiveCard({
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Hello and welcome! With this sample, you can experience the functionality of bot configuration. To access Bot configuration, click on the settings button in the bot description card.",
"wrap": true,
"size": "large",
"weight": "bolder"
},
{
"type": "Image",
"url": `data:image/jpeg;base64,${imageBase64}`,
"size": "auto"
}
],
"fallbackText": "This card requires Adaptive Card support."
});
await context.sendActivity({
text: '',
attachments: [card]
});
await next();
}
/**
* Handles incoming messages.
* @param {TurnContext} context - The context object for the turn.
* @param {Function} next - The next middleware handler to call.
*/
async handleMessage(context, next) {
// By calling next() you ensure that the next BotHandler is run.
await next();
}
/**
* Handles the bot configuration fetch request.
* @param {TurnContext} _context - The context object for the turn.
* @param {Object} _configData - The configuration data.
* @returns {Object} The response object containing the configuration.
*/
async handleTeamsConfigFetch(_context, _configData) {
return {
config: {
type: "auth",
suggestedActions: {
actions: [
{
type: "openUrl",
value: "https://example.com/auth",
title: "Sign in to this app"
}
]
}
}
};
}
/**
* Handles the bot configuration submit request.
* @param {TurnContext} context - The context object for the turn.
* @param {Object} _configData - The configuration data.
* @returns {Object} The response object containing the configuration.
*/
async handleTeamsConfigSubmit(context, _configData) {
return {
config: {
type: 'message',
value: 'You have chosen to finish setting up bot',
}
};
}
}
module.exports.TeamsBot = TeamsBot;