Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.onReceive((context) => {
if (context.request.type === botbuilder.ActivityTypes.message) {
// Check to see if the user said cancel or menu
const utterance = (context.request.text || '').trim();
if (/^cancel/i.test(utterance)) {
endDemo(context);
} else if (/^menu/i.test(utterance)) {
menu(context);
} else {
// Route incoming message to active prompt
return prompts.Prompt.routeTo(context).then((handled) => {
// If no active prompt then start the task
if (!handled) { startDemo(context) }
});
}
}
});
return __awaiter(this, void 0, void 0, function* () {
// Don't do anything for non-message activities
if (dc.context.activity.type !== botbuilder_core_1.ActivityTypes.Message) {
return dialog_1.Dialog.EndOfTurn;
}
// Run next step with the message text as the result.
return yield this.dialogResume(dc, dialog_1.DialogReason.continueCalled, dc.context.activity.text);
});
}
.then(() => {
if (request.type === botbuilder_core_1.ActivityTypes.Invoke) {
// Retrieve cached invoke response.
const invokeResponse = context.services.get(INVOKE_RESPONSE_KEY);
if (invokeResponse && invokeResponse.value) {
const value = invokeResponse.value;
res.send(value.status, value.body);
res.end();
}
else {
throw new Error(`Bot failed to return a valid 'invokeResponse' activity.`);
}
}
else {
res.send(202);
res.end();
}
});
return __awaiter(this, void 0, void 0, function* () {
// Don't do anything for non-message activities
if (dc.context.activity.type !== botbuilder_core_1.ActivityTypes.Message) {
return dialog_1.Dialog.EndOfTurn;
}
// Perform base recognition
const state = dc.activeDialog.state;
const recognized = yield this.onRecognize(dc.context, state.state, state.options);
// Validate the return value
let end = false;
let endResult;
if (this.validator) {
yield this.validator(dc.context, {
recognized: recognized,
state: state.state,
options: state.options,
end: (output) => {
if (end) {
throw new Error(`PromptValidatorContext.end(): method already called for the turn.`);
isTeamsVerificationInvoke(context) {
const activity = context.activity;
return activity.type === botbuilder_core_1.ActivityTypes.Invoke && activity.name == "signin/verifyState";
}
channelSupportsOAuthCard(channelId) {
return __awaiter(this, void 0, void 0, function* () {
let token;
if (this.isTokenResponseEvent(context)) {
token = context.activity.value;
}
else if (this.isTeamsVerificationInvoke(context)) {
const code = context.activity.value.state;
yield context.sendActivity({ type: 'invokeResponse', value: { status: 200 } });
token = yield this.getUserToken(context, code);
}
else if (context.activity.type === botbuilder_core_1.ActivityTypes.Message) {
const matched = /(\d{6})/.exec(context.activity.text);
if (matched && matched.length > 1) {
token = yield this.getUserToken(context, matched[1]);
}
}
return token !== undefined ? { succeeded: true, value: token } : { succeeded: false };
});
}
function next(i) {
if (i < activities.length) {
responses.push({});
let a = activities[i];
switch (a.type) {
case 'delay':
setTimeout(() => next(i + 1), a.value);
break;
case botbuilder_core_1.ActivityTypes.Message:
if (a.attachments && a.attachments.length > 0) {
const append = a.attachments.length === 1 ? `(1 attachment)` : `(${a.attachments.length} attachments)`;
that.print(`${a.text} ${append}`);
}
else {
that.print(a.text);
}
next(i + 1);
break;
default:
that.print(`[${a.type}]`);
next(i + 1);
break;
}
}
else {
isTokenResponseEvent(context) {
const activity = context.activity;
return activity.type === botbuilder_core_1.ActivityTypes.Event && activity.name == "tokens/response";
}
isTeamsVerificationInvoke(context) {