forked from OfficeDev/Microsoft-Teams-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teamsBot.js
85 lines (73 loc) · 2.21 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { TeamsActivityHandler, CardFactory } = require("botbuilder");
const fs = require('fs');
class TeamsBot extends TeamsActivityHandler {
constructor() {
super();
this.onMembersAdded(async (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();
});
this.onMessage(async (context, next) => {
// By calling next() you ensure that the next BotHandler is run.
await next();
});
}
/* Implementing sdk handler for bot configuration
configData object currently doesnt suport any data
*/
async handleTeamsConfigFetch(_context, _configData) {
let response = {};
response = {
config: {
type: "auth",
suggestedActions: {
actions: [
{
type: "openUrl",
value: "https://example.com/auth",
title: "Sign in to this app"
}]
},
},
};
return response;
}
async handleTeamsConfigSubmit(context, _configData) {
let response = {};
response = {
config: {
type: 'message',
value: 'You have chosen to finish setting up bot',
},
}
return response;
}
}
module.exports.TeamsBot = TeamsBot;