Giter Site home page Giter Site logo

wictorwilen / botbuilder-teams-messagingextensions Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 6.0 620 KB

Microsoft Teams Messaging Extension Middleware for Microsoft Bot Builder

License: MIT License

TypeScript 99.18% JavaScript 0.82%
microsoft-teams botbuilder msteams botbuilder-framework botbuilder-extension

botbuilder-teams-messagingextensions's People

Contributors

hughtroeger avatar kavins14 avatar tdwhite0 avatar wictorwilen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

botbuilder-teams-messagingextensions's Issues

Unable to trigger a task module from onSubmitAction

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:

index - line 267

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 }}],
                })
            }
        });
    }

}

botMessagePreview functionality does not work completely

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:

case "composeExtension/submitAction":
if ((this.commandId === context.activity.value.commandId || this.commandId === undefined) &&
this.processor.onSubmitAction) {
try {
const result = await this.processor.onSubmitAction(context, context.activity.value);
context.sendActivity({
type: INVOKERESPONSE,
value: {
body: {
composeExtension: result,
},
status: 200,
},
});

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.

Few Questions

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.

onTurn doesn't check if context.activity.value is defined before accessing context.activity.value.commandId

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.