MicrosoftDocs / msteams-docs

Source for the Microsoft Teams developer platform documentation.
https://aka.ms/teamsdev
Creative Commons Attribution 4.0 International
281 stars 502 forks source link

How to send adaptive card directly into chat as a message from bot in a message extension. #11418

Open Wajeed-msft opened 1 month ago

Wajeed-msft commented 1 month ago

Discussed in https://github.com/MicrosoftDocs/msteams-docs/discussions/8879

Originally posted by **sn-007** June 19, 2023 Hey, I am working on an action-based messaging extension app for teams. My action can be invoked from a message. After submitting the action, currently the adaptive card I am sending is getting inserted into the chat and the user must manually click on send. I want the message to be directly inserted into the chat. [Microsoft documentation](https://learn.microsoft.com/en-us/microsoftteams/platform/messaging-extensions/how-to/action-commands/define-action-command#select-how-the-final-message-is-sent ) says, "_If the message extension is invoked from the compose box or directly from a message, your web service can insert the final response directly into the channel or chat. In this case, the Adaptive Card comes from the bot, the bot updates it, and replies to the conversation thread if needed. You must add the bot object to the app manifest using the same ID and defining the appropriate scopes._" But I have no idea how to do this. Yes, we will add the bot to manifest, what next? Currently, I am returning my adaptive card using the following code : ``` async function executeActions(context, action) { const data = action.data; const flaskData = await postFlaskData("/jstack", data); const adaptiveCard = createAdaptiveCardJstack(flaskData, "Jstack"); const attachment = { contentType: adaptiveCard.contentType, content: adaptiveCard.content, preview: adaptiveCard, }; return { composeExtension: { type: "result", attachmentLayout: "list", attachments: [attachment], } }; }; ``` In this code "executesActions" is a action that will be called from the handleMessagingExtensionSubmitAction like this: ``` async handleTeamsMessagingExtensionSubmitAction(context, action) { switch (action.commandId) { case "executeActions": return await executeActions(context, action); default: throw new Error("NotImplemented"); } } ``` Could someone please help how can I tweak the codes, to send messages into the chat directly? So that, the user should not have to click on send every time. I don't mind if the message comes from a bot, into the chat. I am thinking of something like context.sendActivity(), but not sure how to use this. Thanks for you time.
microsoft-github-policy-service[bot] commented 1 month ago

Hi Wajeed-msft! Thank you for bringing this issue to our attention. We will investigate and if we require further information we will reach out in one business day. Please use this link to escalate if you don't get replies.

Best regards, Teams Platform

sayali-MSFT commented 1 month ago

@sn-007 Thanks for reporting your issue. We will check this at our end and will get back to you.

sayali-MSFT commented 1 month ago

@sn-007-Here is a sample of how to send the card directly to a channel without using the compose box and sending manually:

Sample Code

microsoft-github-policy-service[bot] commented 3 days ago

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 3 days. It will be closed if no further activity occurs within 3 days of this comment.