Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async initialStep(stepContext: WaterfallStepContext): Promise {
const timex = (stepContext.options as any).date;
const promptMessageText = 'On what date would you like to travel?';
const promptMessage = MessageFactory.text(promptMessageText, promptMessageText, InputHints.ExpectingInput);
const repromptMessageText = 'I\'m sorry, for best results, please enter your travel date including the month, day and year.';
const repromptMessage = MessageFactory.text(repromptMessageText, repromptMessageText, InputHints.ExpectingInput);
if (!timex) {
// We were not given any date at all so prompt the user.
return await stepContext.prompt(DATETIME_PROMPT,
{
prompt: promptMessage,
retryPrompt: repromptMessage
});
}
// We have a Date we just need to check it is unambiguous.
const timexProperty = new TimexProperty(timex);
if (!timexProperty.types.has('definite')) {
// This is essentially a "reprompt" of the data we were given up front.
private makeOutgoing(line, vars) {
let outgoing;
if (line.quick_replies) {
outgoing = MessageFactory.suggestedActions(line.quick_replies.map((reply) => { return { type: ActionTypes.PostBack, title: reply.title, text: reply.payload, displayText: reply.title, value: reply.payload}; }), line.text[0]);
} else {
outgoing = MessageFactory.text(line.text[Math.floor(Math.random()*line.text.length)]);
}
// handle slack attachments
if (line.attachments) {
outgoing.channelData = {
attachments: line.attachments,
};
}
// handle teams attachments
if (line.platforms && line.platforms.teams) {
if (line.platforms.teams.attachments) {
outgoing.attachments = line.platforms.teams.attachments.map((a) => {
a.content = {...a};
a.contentType = 'application/vnd.microsoft.card.' + a.type;
return a;
async confirmStep(stepContext) {
const bookingDetails = stepContext.options;
// Capture the results of the previous step
bookingDetails.travelDate = stepContext.result;
const messageText = `Please confirm, I have you traveling to: ${ bookingDetails.destination } from: ${ bookingDetails.origin } on: ${ bookingDetails.travelDate }. Is this correct?`;
const msg = MessageFactory.text(messageText, messageText, InputHints.ExpectingInput);
// Offer a YES/NO prompt.
return await stepContext.prompt(CONFIRM_PROMPT, { prompt: msg });
}
async initialStep(stepContext) {
const timex = stepContext.options.date;
const promptMessageText = 'On what date would you like to travel?';
const promptMessage = MessageFactory.text(promptMessageText, promptMessageText, InputHints.ExpectingInput);
const repromptMessageText = "I'm sorry, for best results, please enter your travel date including the month, day and year.";
const repromptMessage = MessageFactory.text(repromptMessageText, repromptMessageText, InputHints.ExpectingInput);
if (!timex) {
// We were not given any date at all so prompt the user.
return await stepContext.prompt(DATETIME_PROMPT,
{
prompt: promptMessage,
retryPrompt: repromptMessage
});
}
// We have a Date we just need to check it is unambiguous.
const timexProperty = new TimexProperty(timex);
if (!timexProperty.types.has('definite')) {
// This is essentially a "reprompt" of the data we were given up front.
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) {
await context.sendActivity(MessageFactory.text('Welcome to QnA Bot'));
}
}
// By calling next() you ensure that the next BotHandler is run.
await next();
});
}
// otherwise, if it is an array, pick a random element
if (line.text && typeof(line.text) === 'string') {
text = line.text;
// If text is a function, call the function to get the actual text value.
} else if (line.text && typeof(line.text) === 'function') {
text = await line.text(line, vars);
} else if (Array.isArray(line.text)) {
text = line.text[Math.floor(Math.random() * line.text.length)];
}
/*******************************************************************************************************************/
// use Bot Framework's message factory to construct the initial object.
if (line.quick_replies && typeof(line.quick_replies) != 'function') {
outgoing = MessageFactory.suggestedActions(line.quick_replies.map((reply) => { return { type: ActionTypes.PostBack, title: reply.title, text: reply.payload, displayText: reply.title, value: reply.payload }; }), text);
} else {
outgoing = MessageFactory.text(text);
}
outgoing.channelData = outgoing.channelData ? outgoing.channelData : {};
/*******************************************************************************************************************/
// allow dynamic generation of quick replies and/or attachments
if (typeof(line.quick_replies)=='function') {
// set both formats of quick replies
outgoing.channelData.quick_replies = await line.quick_replies(line, vars);
outgoing.suggestedActions = {actions: outgoing.channelData.quick_replies.map((reply) => { return { type: ActionTypes.PostBack, title: reply.title, text: reply.payload, displayText: reply.title, value: reply.payload }; }) };
}
if (typeof(line.attachment)=='function') {
outgoing.channelData.attachment = await line.attachment(line, vars);
}
if (typeof(line.attachments)=='function') {
// set both locations for attachments
async mentionActivityAsync(context) {
const mention = {
mentioned: context.activity.from,
text: `${ new TextEncoder().encode(context.activity.from.name) }`,
type: 'mention'
};
const replyActivity = MessageFactory.text(`Hi ${ mention.text }`);
replyActivity.entities = [mention];
await context.sendActivity(replyActivity);
}
members.forEach(async (teamMember) => {
const message = MessageFactory.text(`Hello ${ teamMember.givenName } ${ teamMember.surname }. I'm a Teams conversation bot.`);
var ref = TurnContext.getConversationReference(context.activity);
ref.user = teamMember;
await context.adapter.createConversation(ref,
async (t1) => {
const ref2 = TurnContext.getConversationReference(t1.activity);
await t1.adapter.continueConversation(ref2, async (t2) => {
await t2.sendActivity(message);
});
});
});
await context.sendActivity(MessageFactory.text('All messages have been sent.'));
}
}
async destinationStep(stepContext) {
const bookingDetails = stepContext.options;
if (!bookingDetails.destination) {
const messageText = 'To what city would you like to travel?';
const msg = MessageFactory.text(messageText, messageText, InputHints.ExpectingInput);
return await stepContext.prompt(TEXT_PROMPT, { prompt: msg });
}
return await stepContext.next(bookingDetails.destination);
}