We've been using Botbuilder.js version 4.15.0 for our Teams Bot.
When user invoke task module using task/fetch
, Bot calls handleTeamsTaskModuleFetch
handler and respond with 501 because invokeResponse
is undefined
(see botFrameworkAdapter) and right after that it tries to respond with 200 and req.body
with actual task
which leads to this error:
UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Messenger Bot:
export class MessengerBot extends TeamsActivityHandler {
constructor() {
super();
this.onMessage(async (context, next) => {
this.handleMessage(context);
await next();
});
}
async handleMessage(context: TurnContext) {
const activity = MessageFactory.attachment(CardFactory.adaptiveCard({
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json',
version: '1.5',
type: 'AdaptiveCard',
body: [
{
type: 'TextBlock',
text: 'Task Module Invocation from Adaptive Card',
weight: 'bolder',
size: 3
}
],
actions: [{
type: 'Action.Submit',
title: 'Open',
data: {
msteams: { type: 'task/fetch' },
data: {
foo: 'bar'
}
}
}]
}));
activity.summary = 'Open URL';
await context.sendActivity(activity);
}
async handleTeamsTaskModuleFetch(context: TurnContext, taskModuleRequest: TaskModuleRequest): Promise<TaskModuleResponse> {
const url = 'https://some valid domain to navigate to'; // Domain included in "validDomains" and use HTTPS
return {
task: {
type: 'continue',
value: {
title: 'Create Ticket',
height: 700,
width: 700,
fallbackUrl: url,
url: url
},
},
};
}
async handleTeamsTaskModuleSubmit(context: TurnContext, taskModuleRequest: TaskModuleRequest): Promise<TaskModuleResponse> {
return {
task: {
type: 'message',
value: 'Thanks!'
}
};
}
}
How can I find out the cause of this error? Appreciate any ideas!