Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async beginDialog(dc, options) {
// Format help card and message
const card = CardFactory.heroCard(getText('en', 'help_title'), undefined, ['Roll Dice', 'Play Craps']);
const msg = MessageFactory.attachment(card);
msg.speak = ssml.speak(getText('en', 'help_ssml'));
msg.inputHint = InputHints.AcceptingInput;
// Send card and end dialog
await dc.context.sendActivity(msg);
return await dc.endDialog();
}
}
// Process the message by checking the Activity.Text. The FacebookQuickReply could also contain a json payload.
// Initially the bot offers to showcase 3 Facebook features: Quick replies, PostBack and getting the Facebook Page Name.
switch (turnContext.activity.text) {
// Here we showcase how to obtain the Facebook page id.
// This can be useful for the Facebook multi-page support provided by the Bot Framework.
// The Facebook page id from which the message comes from is in turnContext.Activity.Recipient.Id.
case facebookPageIdOption:
await turnContext.sendActivity(`This message comes from the following Facebook Page: ${ turnContext.activity.recipient.id }`);
await this.showChoices(turnContext);
break;
// Here we send a HeroCard with 2 options that will trigger a Facebook PostBack.
case postBackOption:
var card = CardFactory.heroCard(
'Is 42 the answer to the ultimate question of Life, the Universe, and Everything?',
null,
CardFactory.actions([
{
type: ActionTypes.PostBack,
title: 'Yes',
value: 'Yes'
},
{
type: ActionTypes.PostBack,
title: 'No',
value: 'No'
}
])
);
private createHeroCard() {
return CardFactory.heroCard(
'BotFramework Hero Card',
CardFactory.images(['https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg']),
CardFactory.actions([
{
title: 'Get started',
type: 'openUrl',
value: 'https://docs.microsoft.com/en-us/azure/bot-service/'
}
])
);
}
async sendIntroCard(context) {
const card = CardFactory.heroCard(
'Welcome to Bot Framework!',
'Welcome to Welcome Users bot sample! This Introduction card is a great way to introduce your Bot to the user and suggest some things to get them started. We use this opportunity to recommend a few next steps for learning more creating and deploying bots.',
['https://aka.ms/bf-welcome-card-image'],
[
{
type: ActionTypes.OpenUrl,
title: 'Get an overview',
value: 'https://docs.microsoft.com/en-us/azure/bot-service/?view=azure-bot-service-4.0'
},
{
type: ActionTypes.OpenUrl,
title: 'Ask a question',
value: 'https://stackoverflow.com/questions/tagged/botframework'
},
{
type: ActionTypes.OpenUrl,
switch (context.activity.text.trim()) {
case 'MentionMe':
await this.mentionActivityAsync(context);
break;
case 'UpdateCardAction':
await this.updateCardActivityAsync(context);
break;
case 'Delete':
await this.deleteCardActivityAsync(context);
break;
case 'MessageAllMembers':
await this.messageAllMembersAsync(context);
break;
default:
const value = { count: 0 };
const card = CardFactory.heroCard(
'Welcome Card',
null,
[
{
type: ActionTypes.MessageBack,
title: 'Update Card',
value: value,
text: 'UpdateCardAction'
},
{
type: ActionTypes.MessageBack,
title: 'Message all members',
value: null,
text: 'MessageAllMembers'
}]);
await context.sendActivity({ attachments: [card] });
static getHeroCard(buttons: string[], cardTitle: string): Partial {
const cardActions: CardAction[] = [];
buttons.forEach(element => {
cardActions.push({
value: element,
type: 'imBack',
title: element
});
});
const heroCard: Attachment = CardFactory.heroCard(
cardTitle,
[],
CardFactory.actions(cardActions));
return { attachments: [heroCard] };
}
static GetQnAPromptsCard(result) {
var cardActions = [];
result.context.prompts.forEach(prompt => {
cardActions.push({
value: prompt.displayText,
type: ActionTypes.ImBack,
title: prompt.displayText
});
});
var heroCard = CardFactory.heroCard('', result.answer, [], CardFactory.actions(cardActions));
return { attachments: [heroCard] };
}
createHeroCard() {
return CardFactory.heroCard(
'BotFramework Hero Card',
CardFactory.images(['https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg']),
CardFactory.actions([
{
type: 'openUrl',
title: 'Get started',
value: 'https://docs.microsoft.com/en-us/azure/bot-service/'
}
])
);
}
function createHeroCard() {
return CardFactory.heroCard(
'BotFramework Hero Card',
CardFactory.images(['https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg']),
CardFactory.actions([
{
type: 'openUrl',
title: 'Get Started',
value: 'https://docs.microsoft.com/en-us/azure/bot-service/'
}
])
);
}
response.data.objects.forEach(obj => {
const heroCard = CardFactory.heroCard(obj.package.name);
const preview = CardFactory.heroCard(obj.package.name);
preview.content.tap = { type: 'invoke', value: { description: obj.package.description } };
attachments.push({ ...heroCard, preview });
});
}