Universal Actions Model code sample - Project Management
This sample illustrates the Universal Action Model implementation available for adaptive cards version 1.4 or higher.
Prerequisites
- Outlook/OWA client is available and you have an account.
- A valid Azure subscription.
- Understanding of Azure Bot Framework.
Setup for bot
- Register a bot with Azure Bot Service, following the instructions here.
- Ensure that you've enabled the Outlook Channel.
- Open your bot resource in the Azure portal.
- Open the Channels pane.
- Select the Outlook channel in Available Channels section.
- Under the Actionable Messages tab, Click Apply followed by please register here.
- Fill out the registration form to request access. See Register your service with the actionable email developer dashboard for more information.
- Create your bot with the Bot Framework SDK, following the instruction here.
Step 1: Ensure your adaptive card payloads are ready
For the Project management scenario, you can find the JSON payload here. Below, You can see the payload rendering in mobile and desktop screens.
For Universal Actions, you need to use Action.Execute
which gathers input fields and send an Invoke
activity of type adaptiveCard/action
to the target bot. Target bot can identify the the Action done using the verb
field. Any additional input can be sent using the data
field.
JSON payload
Here is a snippet of Actions for Project management scenario.
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Execute",
"title": "Mark complete",
"verb": "markComplete",
"data": {},
"isPrimary": true,
"style": "positive"
},
{
"type": "Action.ShowCard",
"title": "Add a comment",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "Input.Text",
"id": "AddComment",
"placeholder": "Add a comment",
"isMultiline": true
},
{
"type": "ActionSet",
"actions": [
{
"type": "Action.Execute",
"title": "Submit",
"verb": "projectSubmitComment",
"data": "{Reason: {{AddComment.value}}}"
}
]
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"padding": "None"
}
}
],
"spacing": "None"
}
For more information, see Action.Execute schema and properties
Step 2: Write custom business logic in the bot for Project management
In the Azure bot, you can use OnAdaptiveCardInvokeAsync method to capture the action using the verb
field, add your business logic and send the refresh card back to Outlook.
protected override async Task<AdaptiveCardInvokeResponse> OnAdaptiveCardInvokeAsync(
ITurnContext<IInvokeActivity> turnContext,
AdaptiveCardInvokeValue invokeValue,
CancellationToken cancellationToken)
{
try
{
if (invokeValue.Action.Verb == "markComplete")
{
// This function can contain your business logic
// to capture the complete action and show the refresh card
return await ProcessProjectMarkComplete();
}
else if (invokeValue.Action.Verb == "projectSubmitComment")
{
// This function can contain your business logic
// to submit the comment and show the refresh car
return await ProcessProjectSubmitComment();
}
else
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented);
}
}
catch (AdaptiveCardActionException e)
{
throw new InvokeResponseException(HttpStatusCode.NotImplemented, e.Response);
}
}
You can test your bot locally or deploy your bot to Azure.
Step 3: Sending the Actionable Message
You can send the Actionable Message backed by Universal Actions similar to any other Actionable Message. For more information, please see Send an actionable message via email.