forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
46 lines (41 loc) · 1.82 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const { CardFactory } = require('botbuilder');
// Import AdaptiveCard content.
const FlightItineraryCard = require('./resources/FlightItineraryCard.json');
const ImageGalleryCard = require('./resources/ImageGalleryCard.json');
const LargeWeatherCard = require('./resources/LargeWeatherCard.json');
const RestaurantCard = require('./resources/RestaurantCard.json');
const SolitaireCard = require('./resources/SolitaireCard.json');
// Create array of AdaptiveCard content, this will be used to send a random card to the user.
const CARDS = [
FlightItineraryCard,
ImageGalleryCard,
LargeWeatherCard,
RestaurantCard,
SolitaireCard
];
/**
* A bot that sends AdaptiveCards to the user when it receives a message.
*/
class AdaptiveCardsBot {
/**
* Every conversation turn for our AdaptiveCardsBot will call this method.
* There are no dialogs used, since it's "single turn" processing, meaning a single
* request and response, with no stateful conversation.
* @param turnContext A TurnContext instance containing all the data needed for processing this conversation turn.
*/
async onTurn(context) {
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types.
if (context.activity.type === 'message') {
const randomlySelectedCard = CARDS[Math.floor((Math.random() * CARDS.length - 1) + 1)];
await context.sendActivity({
text: 'Here is an Adaptive Card:',
attachments: [CardFactory.adaptiveCard(randomlySelectedCard)]
});
} else {
await context.sendActivity(`[${ context.activity.type } event detected]`);
}
}
}
exports.AdaptiveCardsBot = AdaptiveCardsBot;