Search code examples
botframeworkmicrosoft-teams

How to open url in messaging extension?


I have updated my bot builder package from 4.6.0 to 4.9.0 i.e., the latest version. We have handleTeamsMessagingExtensionFetchTask method which returns a promise. The return type is changed in version 4.9.0. The return type right now is the Promise of MessagingExtensionActionResponse. With this return type, there is no way indicated in the documentation regarding opening a URL. I have added the return type I was using in version 4.6.0 and that was working fine but it seems like there's no way in current update for performing such operations.

return await {
    task: {
        type: 'continue', value: {
            width: 450,
            height: 600,
            title: 'Abc'
            url: '********',
            fallbackUrl: '*******'
        }
    }
} as MessagingExtensionActionResponse;

Solution

  • Initiate a message extension with open action URL. Please find the below piece of code

    protected override async Task<MessagingExtensionActionResponse> OnTeamsMessagingExtensionFetchTaskAsync(ITurnContext<IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
    {
        var response = new MessagingExtensionActionResponse()
        {
            Task = new TaskModuleContinueResponse()
            {
                Value = new TaskModuleTaskInfo()
                {
                    Height = 720,
                    Width = 900,
                    Title = "Testing ME with URL,
                    Url = "https://1f0bd229.ngrok.io/myPage"
                },
            },
        };
        
        return response;
    }
    

    Let me know if this doesn't help you out