Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const pair = kv.split('=');
switch (pair[0]) {
case 'cid':
args['conversationId'] = decodeURIComponent(args[1]);
break;
case 'url':
args['serviceUrl'] = decodeURIComponent(args[1]);
break;
}
});
}
}
// Map to invoke activity
let activity: Partial = {
type: ActivityTypes.Invoke,
name: method,
value: args
};
// Add body contents to args
switch (method) {
case BotFrameworkInvokeMethods.CreateConversation:
activity.value.parameters = await parseBody(req);
break;
case BotFrameworkInvokeMethods.SendConversationHistory:
activity.value.history = await parseBody(req);
break;
case BotFrameworkInvokeMethods.UploadAttachment:
activity.value.attachmentUpload = await parseBody(req);
break;
case BotFrameworkInvokeMethods.SendToConversation:
protected async onTurnActivity(context: TurnContext): Promise {
switch (context.activity.type) {
case ActivityTypes.Invoke:
const invokeResponse = await this.onInvokeActivity(context);
// If onInvokeActivity has already sent an InvokeResponse, do not send another one.
if (invokeResponse && !context.turnState.get(INVOKE_RESPONSE_KEY)) {
await context.sendActivity({ value: invokeResponse, type: 'invokeResponse' });
}
break;
default:
await super.onTurnActivity(context);
break;
}
}
status = 400;
const request = await parseRequest(req);
// Authenticate the incoming request
status = 401;
const authHeader: string = req.headers.authorization || req.headers.Authorization || '';
await this.authenticateRequest(request, authHeader);
// Process received activity
status = 500;
const context: TurnContext = this.createContext(request);
context.turnState.set(BotCallbackHandlerKey, logic);
await this.runMiddleware(context, logic);
// Retrieve cached invoke response.
if (request.type === ActivityTypes.Invoke) {
const invokeResponse: any = context.turnState.get(INVOKE_RESPONSE_KEY);
if (invokeResponse && invokeResponse.value) {
const value: InvokeResponse = invokeResponse.value;
status = value.status;
body = value.body;
} else {
status = 501;
}
} else {
status = 200;
}
} catch (err) {
// Catch the error to try and throw the stacktrace out of processActivity()
processError = err;
body = err.toString();
}
const authHeader: string = req.headers.authorization || req.headers.Authorization || '';
const identity = await this.authenticateRequestInternal(request, authHeader);
// Process received activity
status = 500;
const context: TurnContext = this.createContext(request);
context.turnState.set(this.BotIdentityKey, identity);
const connectorClient = await this.createConnectorClientWithIdentity(request.serviceUrl, identity);
context.turnState.set(this.ConnectorClientKey, connectorClient);
context.turnState.set(BotCallbackHandlerKey, logic);
await this.runMiddleware(context, logic);
// Retrieve cached invoke response.
if (request.type === ActivityTypes.Invoke) {
const invokeResponse: any = context.turnState.get(INVOKE_RESPONSE_KEY);
if (invokeResponse && invokeResponse.value) {
const value: InvokeResponse = invokeResponse.value;
status = value.status;
body = value.body;
} else {
status = 501;
}
} else {
status = 200;
}
} catch (err) {
// Catch the error to try and throw the stacktrace out of processActivity()
processError = err;
body = err.toString();
}
private isTeamsVerificationInvoke(context: TurnContext): boolean {
const activity: Activity = context.activity;
return activity.type === ActivityTypes.Invoke && activity.name === 'signin/verifyState';
}