Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async sendRemoteTokenRequestEvent(turnContext: TurnContext): Promise {
// We trigger a Token Request from the Parent Bot by sending a "TokenRequest" event back and then waiting for a "TokenResponse"
const response: Activity = ActivityExtensions.createReply(turnContext.activity);
response.type = ActivityTypes.Event;
response.name = 'tokens/request';
// Send the tokens/request Event
await this.sendActivities(turnContext, [response]);
}
}
public async onTurn(turnContext: TurnContext, next: () => Promise): Promise {
const activity: Activity = turnContext.activity;
if (activity !== undefined && activity.type === ActivityTypes.Event) {
if (activity.name === SkillEvents.cancelAllSkillDialogsEventName) {
// when skill receives a CancelAllSkillDialogsEvent, clear the dialog stack and short-circuit
const currentConversation: DialogState|undefined = await this.dialogStateAccessor.get(turnContext, { dialogStack: [] });
if (currentConversation !== undefined) {
currentConversation.dialogStack = [];
await this.dialogStateAccessor.set(turnContext, currentConversation);
await this.conversationState.saveChanges(turnContext, true);
}
return;
}
}
await next();
}
public async sendRemoteTokenRequestEvent(turnContext: TurnContext): Promise {
// We trigger a Token Request from the Parent Bot by sending a "TokenRequest" event back and then waiting for a "TokenResponse"
const response: Activity = ActivityExtensions.createReply(turnContext.activity);
response.type = ActivityTypes.Event;
response.name = TokenEvents.tokenRequestEventName;
// Send the tokens/request Event
await this.sendActivities(turnContext, [response]);
}
action: async (request: ReceiveRequest, routeData: Object): Promise => {
// MISSING Check response converter
const bodyParts: string[] = await Promise.all(request.Streams.map
((s: ContentStream): Promise => s.readAsJson()));
const body: string = bodyParts.join();
// eslint-disable-next-line @typescript-eslint/tslint/config
const activity: Activity = JSON.parse(body);
if (activity === undefined) {
throw new Error('Error deserializing activity response!');
}
if (activity.type === ActivityTypes.Event && activity.name === TokenEvents.tokenRequestEventName) {
if (this.tokenRequestHandler !== undefined) {
await this.tokenRequestHandler(activity);
return { id: '' };
} else {
throw new Error('Skill is requesting for token but there\'s no handler on the calling side!');
}
} else if (activity.type === ActivityTypes.Handoff) {
if (this.handoffActivityHandler !== undefined) {
await this.handoffActivityHandler(activity);
return { id: '' };
} else {
throw new Error('Skill is sending handoff activity but there\'s no handler on the calling side!');
}
} else {
public async onTurn(turnContext: TurnContext, next: () => Promise): Promise {
const activity: Activity = turnContext.activity;
if (activity.type === ActivityTypes.Message) {
const text: string = activity.text;
const value: string = JSON.stringify(activity.value);
if (text && text.startsWith('/event:')) {
const json: string = text.substr('/event:'.length);
// eslint-disable-next-line @typescript-eslint/tslint/config
const body: Activity = JSON.parse(json);
turnContext.activity.type = ActivityTypes.Event;
turnContext.activity.name = body.name || turnContext.activity.name;
turnContext.activity.text = body.text || turnContext.activity.text;
turnContext.activity.value = body.value || turnContext.activity.value;
}
if (value && value.includes('event')) {
// eslint-disable-next-line @typescript-eslint/tslint/config
const body: { event: { name: string; text: string; value: string }} = JSON.parse(value);
turnContext.activity.type = ActivityTypes.Event;
if (body.event !== undefined) {
if (body.event.name !== undefined) {
turnContext.activity.name = body.event.name;
}
if (body.event.text !== undefined) {
turnContext.activity.text = body.event.text;
public async cancelRemoteDialogs(turnContext: TurnContext): Promise {
const cancelRemoteDialogEvent: Activity = ActivityExtensions.createReply(turnContext.activity);
cancelRemoteDialogEvent.type = ActivityTypes.Event;
cancelRemoteDialogEvent.name = SkillEvents.cancelAllSkillDialogsEventName;
await this.forwardToSkill(turnContext, cancelRemoteDialogEvent);
}
const value: string = JSON.stringify(activity.value);
if (text && text.startsWith('/event:')) {
const json: string = text.substr('/event:'.length);
const body: Activity = JSON.parse(json);
turnContext.activity.type = ActivityTypes.Event;
turnContext.activity.name = body.name || turnContext.activity.name;
turnContext.activity.text = body.text || turnContext.activity.text;
turnContext.activity.value = body.value || turnContext.activity.value;
}
if (value && value.includes('event')) {
const body: { event: { name: string; text: string; value: string }} = JSON.parse(value);
turnContext.activity.type = ActivityTypes.Event;
if (body.event !== undefined) {
if (body.event.name !== undefined) {
turnContext.activity.name = body.event.name;
}
if (body.event.text !== undefined) {
turnContext.activity.text = body.event.text;
}
if (body.event.value !== undefined) {
turnContext.activity.value = body.event.value;
}
}
}
}
return next();
}
protected async onRecognize(context: TurnContext, state: object, options: PromptOptions): Promise> {
const result: PromptRecognizerResult = { succeeded: false };
const activity: Activity = context.activity;
if (activity.type === ActivityTypes.Event && activity.name === this.eventName) {
result.succeeded = true;
result.value = activity;
}
return Promise.resolve(result);
}
}
public async cancelRemoteDialogs(turnContext: TurnContext): Promise {
const cancelRemoteDialogEvent: Activity = ActivityExtensions.createReply(turnContext.activity);
cancelRemoteDialogEvent.type = ActivityTypes.Event;
cancelRemoteDialogEvent.name = SkillEvents.cancelAllSkillDialogsEventName;
await this.forwardToSkill(turnContext, cancelRemoteDialogEvent);
}