-
Notifications
You must be signed in to change notification settings - Fork 0
/
logoutDialog.js
61 lines (51 loc) · 2.14 KB
/
logoutDialog.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { ActivityTypes } = require('botbuilder');
const { ComponentDialog } = require('botbuilder-dialogs');
class LogoutDialog extends ComponentDialog {
constructor(id, connectionName) {
super(id);
this.connectionName = connectionName;
}
async onBeginDialog(innerDc, options) {
const result = await this.interrupt(innerDc);
if (result) {
return result;
}
return await super.onBeginDialog(innerDc, options);
}
async onContinueDialog(innerDc) {
const result = await this.interrupt(innerDc);
if (result) {
return result;
}
return await super.onContinueDialog(innerDc);
}
async interrupt(innerDc) {
if (innerDc.context.activity.type === ActivityTypes.Message) {
const text = innerDc.context.activity.text.toLowerCase();
if (text === 'logout') {
const userTokenClient = innerDc.context.turnState.get(innerDc.context.adapter.UserTokenClientKey);
const { activity } = innerDc.context;
await userTokenClient.signOutUser(activity.from.id, this.connectionName, activity.channelId);
await innerDc.context.sendActivity('You have been signed out.');
return await innerDc.cancelAllDialogs();
}
else if (text === 'hello' || text === 'hi')
{
await innerDc.context.sendActivity('Hello, checking if current user is valid');
}
else if (text === 'help' || text === 'start')
{
await innerDc.context.sendActivity('Please try say Hello or Logout');
return await innerDc.cancelAllDialogs();
}
else if (text === 'stop' || text === 'cancel')
{
await innerDc.context.sendActivity('Cancel dialog sessions');
return await innerDc.cancelAllDialogs();
}
}
}
}
module.exports.LogoutDialog = LogoutDialog;