wictorwilen / botbuilder-teams-messagingextensions Goto Github PK
View Code? Open in Web Editor NEWMicrosoft Teams Messaging Extension Middleware for Microsoft Bot Builder
License: MIT License
Microsoft Teams Messaging Extension Middleware for Microsoft Bot Builder
License: MIT License
I was trying to trigger a task module from inside the onSubmitAction function (implemented from IMessagingExtensionMiddlewareProcessor) but it will always fail with an error. I trigger this from the command bar (this is the important bit)
I found that MessagingExtensionMiddleware.onTurn
will always return the response of the onSubmitAction
as the value of a composeExtension
property which can be seen here:
switch(...)
...
default:
result = yield this.processor.onSubmitAction(context, context.activity.value);
body = {
composeExtension: result,
};
break;
}
context.sendActivity({
type: INVOKERESPONSE,
value: {
body,
status: 200,
},
});
If I change the composeExtension
to task
then it works fine.
Am I doing something wrong or is there no way to call another task module? Here is a cutdown of my code (this code would work if I done the above change of updating composeExtension
to task
)
export default class HelpDeskMessageExtension implements IMessagingExtensionMiddlewareProcessor {
public async onFetchTask(): Promise<MessagingExtensionResult | TaskModuleContinueResponse | TaskModuleMessageResponse> {
return Promise.resolve<TaskModuleContinueResponse>({
type: "continue",
value: {
url: `${process.env.HostName}/action.html`,
},
});
}
public async onSubmitAction(context: TurnContext): Promise<MessagingExtensionResult> {
return Promise.resolve<MessagingExtensionResult>({
type: "continue",
value: {
card: CardFactory.adaptiveCard({
type: 'AdaptiveCard',
body: [{type: 'TextBlock', text: "text"}],
actions: [{type: 'Action.Submit', title: 'Ok', data: {endFlow: true }}],
})
}
});
}
}
Add support for handling the new invoke event adaptiveCard/action
as per https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/universal-actions-for-adaptive-cards/work-with-universal-actions-for-adaptive-cards
Remove ms-rest-js
package dependency when botbuilder-teams
has fixed the dependency on it.
I'm using the messaging extension middleware to create an action-based command which displays an adaptive card within the task module. The adaptive card has a submit action which triggers the onSubmitAction
function. From there I'm using the botMessagePreview
type in the response. All this works fine but the issue arises when handling submit actions from the Edit
and Submit
buttons from the botMessagePreview
task module. When the Edit
submit action is triggered, onSubmitAction
is run and I want to send the original task module back to the teams client. However for that to work the return value has to be of type TaskModuleContinueResponse
but the function and the middleware does not handle that case.
I figured out that the issue is because of the composeExtension
in the activity being sent on line 244:
botbuilder-teams-messagingextensions/src/index.ts
Lines 235 to 248 in 5cec698
A similar issue also shows up when the Submit
action is triggered but I'm currently working around it by calling sendActivity
from the onSubmitAction
function itself.
Here's the doc detailing the botMessagePreview
functionality.
The botMessagePreview
functionality is cruicial to the application I'm currently building and I would appreciate it if it can be resolved as soon as possible. Also, I can create a PR for this but before that I wanted to know your thoughts on this.
First off wanted to thank you. Super exciting to see some activity on the botbuilder-teams front.
I had a few questions about this middleware as its similar to a solution I created (but didnt think to separate out the response body logic from response very clean solution) and wanted to fully understand everything before switching to utilizing it.
1.) Was there a design decision not to wrap the ITeamsInvokeActivityHandler from the v4 SDK, my only concern would be consistencies between the sdk down the line
2.) Saw references to multiple messaging extensions is this middleware designed for use case of having multiple extensions running through single app? Also I see that middleware short circuits for onSelectItem whats the reason for this? How does it interfere with the SDK
3.) The ability to filter on command line. What kind of use case is this for? Little confused is there a scenario where multiple messaging extension invokes would have same commandId (onQuery, onFetch) or something like that
4.) Any context on when onCardButtonClicked invoke is sent from teams extension. Would this catch any Action Submit/ what would result in extensionSubmit invoke vs this one.
Thanks again! Excited to start utilizing this solution.
I am encountering an error on line 117.
[onTurnError] unhandled error: TypeError: Cannot read property 'commandId' of undefined
In my situation context.activity.value
is undefined
. For background I'm using adapter.continueConversation
, which seems to create an activity with name: continueConversation
but no value.
If I change line 116 to
if (this.commandId !== undefined && context.activity.value !== undefined) {
everything works fine.
Happy to file a PR.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.