使用Outlook Actionable Messages实现简单的审批功能
Posted luoyong0201
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Outlook Actionable Messages实现简单的审批功能相关的知识,希望对你有一定的参考价值。
我是微软Dynamics 365 & Power Platform方面的工程师/顾问罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面的微软最有价值专家(Microsoft MVP),这是我的第479篇原创文章,写于2022年8月27日。
Power Apps的Out-of-Box审批功能我的B站上有介绍,详见 五分钟创建一个审批工作流并在邮件中进行审批测试 。功能很好(也是从本人项目实践应用该功能的精力来讲),还支持移动端,但是偶尔有些特色小需求不是很好实现,比如拒绝的时候要求备注必须输入。这个审批的功能是基于Microsoft Dataverse和 Outlook Actionable Messages 的,今天我就简单做个例子发送Actionable Message到Outlook中。本文借鉴了 Actionable Messages step-by-step 这个视频,如果大家观看不了可以到我的B站去观看。官方文档如下:
- Actionable messages in Outlook and Office 365 Groups
- Get started with actionable messages in Office 365
- Send an actionable message via email in Office 365
- Invoke an Outlook add-in from an actionable message
- Refresh an actionable message when the user opens it
- Security requirements for actionable messages in Office 365
- Designing Outlook Actionable Message cards with the Adaptive Card format
- Register your service with the actionable email developer dashboard
道理不讲太多,就带大家做个最简单的例子。
首先我们准备用户点击邮件中链接/操作执行要调用的Web API。最简单的就是做个Flow来处理,我们用这种最简单的方式。到 https://make.powerautomate.com/ 中的Solution里面新增一个Clou flow:
为Flow取个名字,记得Trigger一定要选择 When an HTTP request is received。
整个Flow如下,很简单,因为我这个是用于演示的,最后一个Response步骤返回的Status Code为200,这样用户点击后会看到成功提示。
保存这个Flow,会生成一个URL,Copy这个URL后面的步骤要用。
然后要到 developer dashboard 去注册一个Provider, 点击 New Provider 链接。
Friendly Name取个有意义的名字即可,Sender email address from which actionable emails will originate 填入Actional Message发送邮件的邮箱,我这里特意创建了一个notification为用户名的邮箱,Target URLs填入前面步骤创建的Cloud flow的URL,这里可以填写多个,也支持正则表达式匹配多个。需要把自动生成的 Provider Id (originator) 字段的值复制下来备用。
至于Scope of submission的话我选第二个Organization,因为我自己就是这个Tenant的Global Admin。然后提交。
提交后Exchange Admin会收到邮件提醒去审批,点击View submission浏览并Approve就可以,批准并生效可能需要点时间,不会超过24小时。
Actionable Message的内容是 Adaptive Card,自己手写太麻烦,有辅助工具,我们这里打开 Adaptive Card Designer ,使用 Expense Approval来创建一个。
因为是演示性质的,所以对于这个Message的内容我也不更改了,直接点击下面的 Edit JSON Payload 链接将JSON内容复制下来。
我这里复制下来的内容如下:
"type": "AdaptiveCard",
"body": [
"type": "ColumnSet",
"style": "emphasis",
"columns": [
"type": "Column",
"items": [
"type": "TextBlock",
"text": "Expense Approval",
"wrap": true
],
"width": "stretch",
"padding": "None"
,
"type": "Column",
"items": [
"type": "TextBlock",
"horizontalAlignment": "Right",
"color": "Accent",
"text": "[#ER-093249-90](https://amdesigner.azurewebsites.net/)",
"wrap": true
],
"width": "stretch",
"padding": "None"
],
"padding": "Default",
"spacing": "None"
,
"type": "Container",
"items": [
"type": "TextBlock",
"size": "Large",
"weight": "Bolder",
"text": "Expense report by Miguel garcia is pending your approval.",
"wrap": true
],
"padding": "Default",
"spacing": "None",
"separator": true
,
"type": "Container",
"id": "7d00f965-40bb-9fc3-ff7b-a9b82a09ead4",
"padding": "Default",
"items": [
"type": "ColumnSet",
"columns": [
"type": "Column",
"items": [
"type": "Image",
"style": "Person",
"url": "https://amdesigner.azurewebsites.net/samples/assets/Miguel_Garcia.png",
"size": "Small",
"altText": "Miguel Garcia Avatar"
],
"width": "auto",
"padding": "None"
,
"type": "Column",
"items": [
"type": "TextBlock",
"text": "Miguel Garcia",
"wrap": true
,
"type": "TextBlock",
"spacing": "None",
"color": "Light",
"text": "Program Manager",
"wrap": true,
"size": "Small"
,
"type": "TextBlock",
"spacing": "None",
"color": "Light",
"text": "Oslo-O365",
"wrap": true,
"size": "Small"
],
"width": "stretch",
"padding": "None"
],
"spacing": "None",
"padding": "None"
],
"spacing": "None",
"separator": true
,
"type": "Container",
"items": [
"type": "TextBlock",
"text": "*\\"Please approve the expenses incurred during my trip to San Francisco for the annual developer conference.\\"*",
"wrap": true
,
"type": "FactSet",
"id": "a46a50e6-11c3-27bb-349f-b40d820a7b83",
"facts": [
"title": "Total Amount:",
"value": "$1,473.35"
,
"title": "Request on:",
"value": "09/21/2019"
]
],
"padding":
"top": "None",
"bottom": "Default",
"left": "Default",
"right": "Default"
,
"spacing": "None"
,
"type": "Container",
"spacing": "None",
"items": [
"type": "Container",
"id": "b149e1cc-0414-662b-6435-ad68d851bf67",
"padding": "Default",
"items": [
"type": "ColumnSet",
"spacing": "None",
"style": "emphasis",
"columns": [
"type": "Column",
"items": [
"type": "TextBlock",
"weight": "Bolder",
"text": "Activity History",
"wrap": true,
"spacing": "None"
],
"width": "stretch",
"spacing": "None",
"padding": "None"
,
"type": "Column",
"id": "ActivityHistoryChevronDown",
"items": [
"type": "Image",
"selectAction":
"type": "Action.ToggleVisibility",
"id": "ExpandActivityHistory",
"title": "Expand Activity History",
"targetElements": [
"ActivityHistoryWrapper",
"ActivityHistoryChevronUp",
"ActivityHistoryChevronDown"
]
,
"url": "https://amdesigner.azurewebsites.net/samples/assets/Down.png",
"width": "20px",
"altText": "Expand",
"height": "20px"
],
"width": "auto",
"spacing": "None",
"padding": "None"
,
"type": "Column",
"id": "ActivityHistoryChevronUp",
"isVisible": false,
"items": [
"type": "Image",
"selectAction":
"type": "Action.ToggleVisibility",
"id": "CollapseActivityHistory",
"title": "Collapse Activity History",
"targetElements": [
"ActivityHistoryWrapper",
"ActivityHistoryChevronUp",
"ActivityHistoryChevronDown"
]
,
"url": "https://amdesigner.azurewebsites.net/samples/assets/Up.png",
"width": "20px",
"altText": "Collapse",
"height": "20px"
],
"width": "auto",
"padding": "None"
],
"padding": "None"
],
"spacing": "None",
"style": "emphasis",
"separator": true,
"selectAction":
"type": "Action.ToggleVisibility",
"targetElements": [
"ActivityHistoryWrapper",
"ActivityHistoryChevronUp",
"ActivityHistoryChevronDown"
],
"id": "ExpandActivityHistory",
"title": "Expand Activity History"
,
"type": "Container",
"id": "ActivityHistoryWrapper",
"isVisible": false,
"items": [
"type": "TextBlock",
"text": "[approved] Collin Ballinger on 02.09.2019",
"wrap": true
,
"type": "TextBlock",
"spacing": "Small",
"text": "[approved] Kat Larrson on 03.09.2019",
"wrap": true
,
"type": "TextBlock",
"spacing": "Small",
"text": "[approved] Daisy Phillips on 03.09.2019",
"wrap": true
,
"type": "TextBlock",
"spacing": "Small",
"color": "Good",
"text": "[pending] Amanda Brady (you)",
"wrap": true
,
"type": "TextBlock",
"spacing": "Small",
"color": "Light",
"text": "[pending] Kevin Sturgis",
"wrap": true
],
"padding":
"top": "Default",
"bottom": "Large",
"left": "Default",
"right": "Default"
,
"spacing": "None",
"separator": true
],
"padding": "None",
"separator": true
,
"type": "Container",
"id": "c8472889-6d94-90e5-5311-3ede0967cd86",
"items": [
"type": "Container",
"spacing": "None",
"separator": true,
"items": [
"type": "ColumnSet",
"columns": [
"type": "Column",
"items": [
"type": "TextBlock",
"weight": "Bolder",
"text": "Expense Details",
"wrap": true,
"spacing": "None"
],
"width": "stretch",
"padding": "None"
,
"type": "Column",
"id": "ExpenseDetailsChevronDown",
"items": [
"type": "Image",
"selectAction":
"type": "Action.ToggleVisibility",
"id": "ExpandExpenseDetails",
"title": "Expand Expense Details",
"targetElements": [
"ExpenseDetailsWrapper",
"ExpenseDetailsChevronUp",
"ExpenseDetailsChevronDown"
]
,
"url": "https://amdesigner.azurewebsites.net/samples/assets/Down.png",
"width": "20px",
"altText": "Expand",
"height": "20px"
],
"width": "auto",
"padding": "None"
,
"type": "Column",
"id": "ExpenseDetailsChevronUp",
"isVisible": false,
"items": [
"type": "Image",
"selectAction":
"type": "Action.ToggleVisibility",
"id": "CollapseExpenseDetails",
"title": "Collapse Expense Details",
"targetElements": [
"ExpenseDetailsWrapper",
"ExpenseDetailsChevronUp",
"ExpenseDetailsChevronDown"
]
,
"url": "https://amdesigner.azurewebsites.net/samples/assets/Up.png",
"width": "20px",
"altText": "Collapse",
"height": "20px"
],
"width": "auto",
"padding": "None"
],
"padding": "None"
],
"padding": "Default",
"style": "emphasis",
"selectAction":
"type": "Action.ToggleVisibility",
"targetElements": [
"ExpenseDetailsWrapper",
"ExpenseDetailsChevronUp",
"ExpenseDetailsChevronDown"
],
"id": "ExpandExpenseDetails",
"title": "Expand Expense Details"
,
"type": "Container",
"id": "ExpenseDetailsWrapper",
"isVisible": false,
"items": [
"type": "ColumnSet",
"columns": [
"type": "Column",
"items": [
"type": "TextBlock",
"horizontalAlignment": "Left",
"text": "1.",
"wrap": true,
"size": "Medium"
],
"width": "auto",
"padding": "None",
"spacing": "None"
,
"type": "Column",
"items": [
"type": "FactSet",
"id": "9d60e7c6-611b-c2b9-b43e-af37c0154ad6",
"facts": [
"title": "Expense Category:",
"value": "Hotel"
,
"title": "Transaction Amount:",
"value": "228.12 USD"
]
],
"width": "stretch",
"spacing": "Small",
"padding": "None"
,
"type": "Column",
"items": [
"type": "FactSet",
"id": "274d7b95-17ae-ff6d-fa93-27568cf0fb2c",
"facts": [
"title": "Transaction date:",
"value": "07/31/2018"
,
"title": "Foreign Currency:",
"value": "228.12 USD"
]
],
"width": "stretch",
"spacing": "Small",
"padding": "None"
],
"padding": "None"
,
"type": "ColumnSet",
"columns": [
"type": "Column",
"items": [
"type": "TextBlock",
"horizontalAlignment": "Left",
"text": "2.",
"wrap": true,
"size": "Medium"
],
"width": "auto",
"padding": "None",
"spacing": "None"
,
"type": "Column",
"items": [
"type": "FactSet",
"id": "96be582e-4971-5a04-a892-e3a9dbf88d40",
"facts": [
"title": "Expense Category:",
"value": "Travel"
,
"title": "Transaction Amount:",
"value": "25.7 USD"
]
],
"width": "stretch",
"spacing": "Small",
"padding": "None"
,
"type": "Column",
"items": [
"type": "FactSet",
"id": "0e2b3791-6d26-c8e8-6b9a-73a41566a1b3",
"facts": [
"title": "Transaction date:",
"value": "08/02/2019"
,
"title": "Foreign Currency:",
"value": "228.12 USD"
]
],
"width": "stretch",
"spacing": "Small",
"padding": "None"
],
"padding": "None",
"separator": true
,
"type": "ColumnSet",
"columns": [
"type": "Column",
"items": [
"type": "TextBlock",
"horizontalAlignment": "Left",
"text": "3.",
"wrap": true,
"size": "Medium"
],
"width": "auto",
"padding": "None",
"spacing": "None"
,
"type": "Column",
"items": [
"type": "FactSet",
"id": "ad183c8c-00b6-f723-977d-5e5fd58a8b16",
"facts": [
"title": "Expense Category:",
"value": "Hotel"
,
"title": "Transaction Amount:",
"value": "205.3 USD"
]
],
"width": "stretch",
"spacing": "Small",以上是关于使用Outlook Actionable Messages实现简单的审批功能的主要内容,如果未能解决你的问题,请参考以下文章