Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]`);
}
}
}
async welcomeUser(turnContext) {
// Do we have any new members added to the conversation?
if (turnContext.activity.membersAdded.length !== 0) {
// Iterate over all new members added to the conversation
for (var idx in turnContext.activity.membersAdded) {
// Greet anyone that was not the target (recipient) of this message
// 'bot' is the recipient for events from the channel,
// turnContext.activity.membersAdded === turnContext.activity.recipient.Id indicates the
// bot was added to the conversation.
if (turnContext.activity.membersAdded[idx].id !== turnContext.activity.recipient.id) {
// Welcome user.
await turnContext.sendActivity(`Hello, I am the Contoso Cafe Bot!`);
await turnContext.sendActivity(`I can help book a table and more..`);
// Send welcome card.
await turnContext.sendActivity(MessageFactory.attachment(CardFactory.adaptiveCard(WelcomeCard)));
}
}
}
}
};
this.onMembersAdded(async (context, next) => {
const membersAdded = context.activity.membersAdded;
for (let cnt = 0; cnt < membersAdded.length; cnt++) {
if (membersAdded[cnt].id !== context.activity.recipient.id) {
const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
await context.sendActivity({ attachments: [welcomeCard] });
await context.sendActivity('This bot will introduce you to translation middleware. Say \'hi\' to get started.');
}
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
// See https://aka.ms/about-bot-activity-message to learn more about the message and other activity types
// Do we have any new members added to the conversation?
if (context.activity.membersAdded.length !== 0) {
// Iterate over all new members added to the conversation
for (var idx in context.activity.membersAdded) {
// Greet anyone that was not the target (recipient) of this message
// the 'bot' is the recipient for events from the channel,
// context.activity.membersAdded == context.activity.recipient.Id indicates the
// bot was added to the conversation.
if (context.activity.membersAdded[idx].id !== context.activity.recipient.id) {
// Welcome user.
// When activity type is "conversationUpdate" and the member joining the conversation is the bot
// we will send our Welcome Adaptive Card. This will only be sent once, when the Bot joins conversation
// To learn more about Adaptive Cards, see https://aka.ms/msbot-adaptivecards for more details.
const welcomeCard = CardFactory.adaptiveCard(WelcomeCard);
await context.sendActivity({ attachments: [welcomeCard] });
}
}
}
}
// make sure to persist state at the end of a turn.
await this.conversationState.saveChanges(context);
await this.userState.saveChanges(context);
}
public static async buildNewUserGreetingCard(turnContext: TurnContext, data: any): Promise {
const introFileName: string = i18next.t('main.introGreetingFile');
const introPath: string = join(__dirname, '..', 'content', introFileName);
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/tslint/config
const introCard: any = JSON.parse(readFileSync(introPath, 'UTF8'));
const attachment: Attachment = CardFactory.adaptiveCard(introCard);
// eslint-disable-next-line @typescript-eslint/tslint/config
const response: Partial = MessageFactory.attachment(attachment, '', attachment.content.speak, InputHints.AcceptingInput);
response.suggestedActions = {
actions: [
{
title: i18next.t('main.helpBtnText1'),
type: ActionTypes.ImBack,
value: i18next.t('main.helpBtnValue1')
},
{
title: i18next.t('main.helpBtnText2'),
type: ActionTypes.ImBack,
value: i18next.t('main.helpBtnValue2')
},
{
async beginDialog(dc, options) {
await dc.context.sendActivity({ attachments: [CardFactory.adaptiveCard(helpCard)] });
await dc.context.sendActivity(`Pick a query from the card or you can use the suggestions below.`);
return await dc.endDialog();
}
}
function createAdaptiveCard() {
return CardFactory.adaptiveCard({
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"type": "AdaptiveCard",
"speak": "Your flight is confirmed for you and 3 other passengers from San Francisco to Amsterdam on Friday, October 10 8:30 AM",
"body": [
{
"type": "TextBlock",
"text": "Passengers",
"weight": "bolder",
"isSubtle": false
},
{
"type": "TextBlock",
"text": "Sarah Hum",
"separator": true
},
public static buildIntroCard(turnContext: TurnContext, data: any): Promise {
const introPath = i18n.__('main.introPath');
const introCard = require(introPath);
const attachment = CardFactory.adaptiveCard(introCard);
const response = MessageFactory.attachment(attachment, '', attachment.content.speak, InputHints.AcceptingInput);
response.suggestedActions = {
actions: [
{
title: i18n.__('main.helpBtnText1'),
type: ActionTypes.ImBack,
value: i18n.__('main.helpBtnValue1')
},
{
title: i18n.__('main.helpBtnText2'),
type: ActionTypes.ImBack,
value: i18n.__('main.helpBtnValue2')
},
{
title: i18n.__('main.helpBtnText3'),
public static adaptiveCard(card: ac.IAdaptiveCard): Attachment {
return CardFactory.adaptiveCard(card);
}
createAdaptiveCardAttachment() {
return CardFactory.adaptiveCard({
version: '1.0.0',
type: 'AdaptiveCard',
body: [
{
type: 'TextBlock',
text: 'Enter Text Here'
},
{
type: 'Input.Text',
id: 'usertext',
placeholder: 'add some text and submit',
IsMultiline: true
}
],
actions: [
{