0

I have a simple Adaptive Card returning into the Teams chat from a TeamsActivityHandler.onMessageActivity override:

 @Override
    protected CompletableFuture<Void> onMessageActivity(TurnContext turnContext) {      
        
        String text = turnContext.getActivity().getText().trim().toLowerCase();     
        
        if(text.contains("calendar")){
            
            File filePath = new File(this.teamsPath, "calCard.json");
            try (InputStream inputStream = new FileInputStream(filePath)) {         
                
                String result = IOUtils.toString(inputStream, StandardCharsets.UTF_8);              
                return turnContext.sendActivity( MessageFactory.attachment(adaptiveCardAttachmentFromJson(result)) )
                .thenApply(resourceResponse -> null);           
                
            } catch (Throwable t) {
                throw new CompletionException(t);
            }
            
        }else{
            return notImplemented();
        }
}

private Attachment adaptiveCardAttachmentFromJson(String json) throws IOException {
        Attachment attachment = new Attachment();
        attachment.setContentType("application/vnd.microsoft.card.adaptive");
        attachment.setContent(new ObjectMapper().readValue(json, ObjectNode.class));
        return attachment;
    }

calCard.json

{   
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "TextBlock",
            "size": "medium",
            "weight": "bolder",
            "text": "Calendar",
            "horizontalAlignment": "center",
            "wrap": true,
            "style": "heading"
        },
        {
            "type": "Input.Text",
            "label": "Matter",
            "id": "MATTER_DETAILS",
            "isRequired": true,
            "errorMessage": "Matter is required",
            "placeholder": "Select a Matter",
            "inlineAction": {
                "type": "Action.Submit",
                "title": "submit",
                "fetchTask": false,
                "data": {
                    "ade_window": "MATTER_PICK",
                    "msteams": {
                        "type": "task/fetch"                                            
                    }
                },
                "id": "MATTER_PICK",
                "associatedInputs": "none"
            }
        },
        {
            "type": "Input.Text",
            "label": "Description",
            "id": "0",
            "name": "CAL_DESC",
            "isRequired": true,
            "errorMessage": "Name is required",
            "placeholder": "Enter a Description"
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Submit"
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3"
}

The card is successfully produced in the chat, and upon clicking the inlineAction Action.Submit button, my bot receives the onTeamsTaskModuleFetch request and I handle with the following logic:

Note: I can hit the ngrok String url shown here from the browser, and I'm also using composeExtensions with commands using this address where the task module is loaded successfully.

  @Override
    protected CompletableFuture<TaskModuleResponse> onTeamsTaskModuleFetch(
        TurnContext turnContext,
        TaskModuleRequest taskModuleRequest
    ) {
         return Async.wrapBlock(() -> {
        
            TaskModuleTaskInfo taskInfo = new TaskModuleTaskInfo();
            
            String url = "https://6303-97-91-136-36.ngrok-free.app/JSP2.5/TeamsStart.jsp?_start_page=Matter%20Detail%20Pick&winTitle=Select%20Matter";
            
            taskInfo.setUrl(url);
            taskInfo.setFallbackUrl(url);       
            taskInfo.setHeight("medium");
            taskInfo.setWidth("small");         
            taskInfo.setTitle("Task Module Test");          
            
            return taskInfo;
        
         }).thenApply(TaskModuleResponseFactory::toTaskModuleResponse);
    }

The web view fails to load and I'm met with an empty Task Module displaying the text "Unable to reach app. Please try again."

Am I missing something?

lfdevjmp
  • 3
  • 4
  • You should check your tags. You've got `C` in there, which seems to be irrelevant, but no mention of `Java`. Feel free to [edit] your question to add more appropriate tags, or indeed for any reason, at any time. – pmacfarlane Jun 14 '23 at 22:06
  • “Unable to reach app. Please try again” error occur due to the reason for this seems the processing time taking more than 15 seconds. You have to manage the long running operations. For proper handling of managing long running operation please refer below doc. https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-long-operations-guidance?view=azure-bot-service-4.0 – Sayali-MSFT Jun 15 '23 at 09:48
  • @Sayali-MSFT 15 seconds? The error message displays almost instantaneously. Also this is a simplified version of the exact sequence of statements as shown in TeamsTaskModuleBot.java onTeamsTaskModuleFetch override in the teamstaskmodule sample project. Is that code incorrect as well? – lfdevjmp Jun 16 '23 at 16:25
  • Could you please look into this sample for reference-https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/8f266c33608d6d7b4cf89c81779ccf49e7664c1e/samples/bot-task-module/java – Sayali-MSFT Jun 19 '23 at 10:02
  • That's the sample I was referencing in my last comment. My code is just a simplified implementation of that very same logic in TeamsTaskModuleBot.java. I have another compose extension in my Teams app that successfully launches a Task Module using the very same URL, but the URL doesn't load into the task module when launched from the adaptive card. – lfdevjmp Jun 19 '23 at 16:47
  • did you get any error in console? – Sayali-MSFT Jul 04 '23 at 08:52

0 Answers0