From fdd2bc8fa63914910703a34117c3f9d1dabaeb70 Mon Sep 17 00:00:00 2001
From: Tony Zhu
Date: Wed, 13 Jun 2018 15:51:22 -0700
Subject: [PATCH] Update the template for the cards
---
action/ActionProcessor.js | 54 ++++--
action/expense_approved.json | 159 +++++++++++++++++
action/expense_declined.json | 159 +++++++++++++++++
action/index.js | 2 +-
action/instruction.html | 326 +++++++++++++++--------------------
5 files changed, 493 insertions(+), 207 deletions(-)
create mode 100644 action/expense_approved.json
create mode 100644 action/expense_declined.json
diff --git a/action/ActionProcessor.js b/action/ActionProcessor.js
index f981167..833825c 100644
--- a/action/ActionProcessor.js
+++ b/action/ActionProcessor.js
@@ -47,26 +47,44 @@ class ActionProcessor{
// You should also return the CARD-ACTION-STATUS header in the response.
// The value of the header will be displayed to the user.
- var card = {
- "type": "AdaptiveCard",
- "version": "1.0",
- "body": [
- {
- "size": "large",
- "text": "Hello " + result.actionPerformer + ". Your action email was from " + result.sender,
- "wrap": true,
- "type": "TextBlock"
- }
- ]
- };
+ var action = body.action;
- cb({
- status: 200,
- headers: {'CARD-UPDATE-IN-BODY': 'true'},
- body: card
- })
- });
+ var comment = body.comment;
+
+ // User's input need to be json encoded to prevent breaking the response json on text replacement
+ comment = JSON.stringify(comment);
+ comment = comment.substr(1, comment.length - 2);
+ // Usually these should be constant from your app config.
+ var originator = body.originator;
+ var actionUrl = body.actionUrl;
+
+ var template = "expense_approved.json";
+
+ if (action === "decline"){
+ template = "expense_declined.json";
+ }
+
+ var fs = require('fs');
+ fs.readFile(__dirname +'/' + template, 'utf8', function (err, data) {
+ if (err) {
+ context.log(err);
+ cb({
+ status: 500,
+ body: err
+ });
+ }
+
+ var cardRaw = data.replace(/\{actionUrl\}/g, actionUrl).replace(/\{originator\}/g, originator).replace(/\{user\}/g, result.actionPerformer).replace(/\{comment\}/g, comment);
+
+ cb({
+ status: 200,
+ headers: {'CARD-UPDATE-IN-BODY': 'true'},
+ body: JSON.parse(cardRaw)
+ });
+ });
+ }
+ );
}
}
diff --git a/action/expense_approved.json b/action/expense_approved.json
new file mode 100644
index 0000000..00dee61
--- /dev/null
+++ b/action/expense_approved.json
@@ -0,0 +1,159 @@
+{
+ "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
+ "type":"AdaptiveCard",
+ "originator":"{originator}",
+ "version":"1.0",
+ "body":[
+ {
+ "type":"ColumnSet",
+ "columns":[
+ {
+ "width":6,
+ "items":[
+ {
+ "type":"Container",
+ "padding":{
+ "left":"small"
+ },
+ "items":[
+ {
+ "type":"Image",
+ "url":"https://filedepot.blob.core.windows.net/build/logo.png"
+ }
+ ]
+ },
+ {
+ "type":"Container",
+ "backgroundImage":"https://filedepot.blob.core.windows.net/build/header.png",
+ "spacing":"small",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"Expense Report (ER-321377) for 1179 USD is available",
+ "size":"medium",
+ "color":"light",
+ "horizontalAlignment":"left",
+ "wrap":true
+ }
+ ]
+ },
+ {
+ "type":"Container",
+ "padding":"small",
+ "items":[
+ {
+ "type":"ColumnSet",
+ "columns":[
+ {
+ "type":"Column",
+ "width":"auto",
+ "items": [
+ {
+ "type":"Image",
+ "id":"action_image",
+ "url":"https://filedepot.blob.core.windows.net/build/approved.png"
+ }
+ ]
+ },
+ {
+ "type":"Column",
+ "width":"auto",
+ "items": [
+ {
+ "type":"TextBlock",
+ "text":"by {user}"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "type":"ColumnSet",
+ "columns":[
+ {
+ "type":"Column",
+ "width":"auto",
+ "items":[
+ {
+ "type":"Image",
+ "url":"https://filedepot.blob.core.windows.net/profile/9.png",
+ "style":"person"
+ }
+ ]
+ },
+ {
+ "type":"Column",
+ "width":"stretch",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"**Miguel Garcia** submitted on 8th May"
+ },
+ {
+ "type":"TextBlock",
+ "text":"Travel & stay expenses for customer visit",
+ "spacing":"none",
+ "size":"small"
+ }
+ ]
+ },
+ {
+ "type":"Column",
+ "width":"auto",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"$1179",
+ "size":"medium",
+ "weight":"bolder"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "type":"ActionSet",
+ "id":"expenseActions",
+ "horizontalAlignment":"left",
+ "actions":[
+ {
+ "type":"Action.Http",
+ "method":"post",
+ "url":"{actionUrl}",
+ "title":"Approve",
+ "body":"{\"action\": \"approve\", \"id\": \"ER-321377\", \"comment\":\"{{comment.value}}\", \"actionUrl\": \"{actionUrl}\", \"originator\": \"{originator}\"}"
+ },
+ {
+ "type":"Action.ShowCard",
+ "title":"Decline",
+ "card":{
+ "type":"AdaptiveCard",
+ "body":[
+ {
+ "type":"Input.Text",
+ "id":"comment",
+ "isMultiline":true,
+ "placeholder":"Comment (optional)"
+ }
+ ],
+ "actions":[
+ {
+ "type":"Action.Http",
+ "method":"post",
+ "url":"{actionUrl}",
+ "title":"OK",
+ "body":"{\"action\": \"decline\", \"id\": \"ER-321377\", \"comment\":\"{{comment.value}}\", \"actionUrl\": \"{actionUrl}\", \"originator\": \"{originator}\"}"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
\ No newline at end of file
diff --git a/action/expense_declined.json b/action/expense_declined.json
new file mode 100644
index 0000000..c5fd98e
--- /dev/null
+++ b/action/expense_declined.json
@@ -0,0 +1,159 @@
+{
+ "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
+ "type":"AdaptiveCard",
+ "originator":"{originator}",
+ "version":"1.0",
+ "body":[
+ {
+ "type":"ColumnSet",
+ "columns":[
+ {
+ "width":6,
+ "items":[
+ {
+ "type":"Container",
+ "padding":{
+ "left":"small"
+ },
+ "items":[
+ {
+ "type":"Image",
+ "url":"https://filedepot.blob.core.windows.net/build/logo.png"
+ }
+ ]
+ },
+ {
+ "type":"Container",
+ "backgroundImage":"https://filedepot.blob.core.windows.net/build/header.png",
+ "spacing":"small",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"Expense Report (ER-321377) for 1179 USD is available",
+ "size":"medium",
+ "color":"light",
+ "horizontalAlignment":"left",
+ "wrap":true
+ }
+ ]
+ },
+ {
+ "type":"Container",
+ "padding":"small",
+ "items":[
+ {
+ "type":"ColumnSet",
+ "columns":[
+ {
+ "type":"Column",
+ "width":"auto",
+ "items": [
+ {
+ "type":"Image",
+ "id":"action_image",
+ "url":"https://filedepot.blob.core.windows.net/build/declined.png"
+ }
+ ]
+ },
+ {
+ "type":"Column",
+ "width":"auto",
+ "items": [
+ {
+ "type":"TextBlock",
+ "text":"by {user} with comment: {comment}"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "type":"ColumnSet",
+ "columns":[
+ {
+ "type":"Column",
+ "width":"auto",
+ "items":[
+ {
+ "type":"Image",
+ "url":"https://filedepot.blob.core.windows.net/profile/9.png",
+ "style":"person"
+ }
+ ]
+ },
+ {
+ "type":"Column",
+ "width":"stretch",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"**Miguel Garcia** submitted on 8th May"
+ },
+ {
+ "type":"TextBlock",
+ "text":"Travel & stay expenses for customer visit",
+ "spacing":"none",
+ "size":"small"
+ }
+ ]
+ },
+ {
+ "type":"Column",
+ "width":"auto",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"$1179",
+ "size":"medium",
+ "weight":"bolder"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "type":"ActionSet",
+ "id":"expenseActions",
+ "horizontalAlignment":"left",
+ "actions":[
+ {
+ "type":"Action.Http",
+ "method":"post",
+ "url":"{actionUrl}",
+ "title":"Approve",
+ "body":"{\"action\": \"approve\", \"id\": \"ER-321377\", \"comment\":\"{{comment.value}}\", \"actionUrl\": \"{actionUrl}\", \"originator\": \"{originator}\"}"
+ },
+ {
+ "type":"Action.ShowCard",
+ "title":"Decline",
+ "card":{
+ "type":"AdaptiveCard",
+ "body":[
+ {
+ "type":"Input.Text",
+ "id":"comment",
+ "isMultiline":true,
+ "placeholder":"Comment (optional)"
+ }
+ ],
+ "actions":[
+ {
+ "type":"Action.Http",
+ "method":"post",
+ "url":"{actionUrl}",
+ "title":"OK",
+ "body":"{\"action\": \"decline\", \"id\": \"ER-321377\", \"comment\":\"{{comment.value}}\", \"actionUrl\": \"{actionUrl}\", \"originator\": \"{originator}\"}"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
\ No newline at end of file
diff --git a/action/index.js b/action/index.js
index 050974a..914c47a 100644
--- a/action/index.js
+++ b/action/index.js
@@ -12,7 +12,7 @@ module.exports = function (context, req) {
}
else {
- fs = require('fs');
+ var fs = require('fs');
fs.readFile(__dirname +'/instruction.html', 'utf8', function (err, data) {
if (err) {
context.log(err);
diff --git a/action/instruction.html b/action/instruction.html
index 6f5db06..da7e71c 100644
--- a/action/instruction.html
+++ b/action/instruction.html
@@ -14,194 +14,144 @@
Please copy the following template to the playground and send it to yourself by clicking "Send via email" button
{
- "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
- "type": "AdaptiveCard",
- "originator": "{originator}",
- "version": "1.0",
- "style": "emphasis",
- "body": [
- {
- "type": "Container",
- "bleed": true,
- "items": [
- {
- "type": "ColumnSet",
- "columns": [
- {
- "width": "auto",
- "verticalContentAlignment": "center",
- "items": [
- {
- "type": "Image",
- "height": "30px",
- "url": "https://cdn2.hubspot.net/hubfs/443262/header_assets/engage_logo.png?t=1459547965461"
- }
- ]
- },
- {
- "width": "stretch",
- "verticalContentAlignment": "center",
- "items": [
- {
- "type": "TextBlock",
- "text": "All survey responses are anonymous. [Learn more](http://www.tinypulse.com)",
- "horizontalAlignment": "right",
- "wrap": true
- }
- ]
- }
- ]
- }
+ "$schema":"http://adaptivecards.io/schemas/adaptive-card.json",
+ "type":"AdaptiveCard",
+ "originator":"",
+ "version":"1.0",
+ "body":[
+ {
+ "type":"ColumnSet",
+ "columns":[
+
+ {
+ "width":1,
+ "items":[
+ {
+ "type":"Container",
+ "padding":{
+ "left":"small"
+ },
+ "items":[
+ {
+ "type":"Image",
+ "url":"https://filedepot.blob.core.windows.net/build/logo.png"
+ }
+ ]
+ },
+ {
+ "type":"Container",
+ "backgroundImage":"https://filedepot.blob.core.windows.net/build/header.png",
+ "spacing":"small",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"Expense Report (ER-321377) for 1179 USD is available",
+ "size":"medium",
+ "color":"light",
+ "horizontalAlignment":"left",
+ "wrap":true
+ }
+ ]
+ },
+ {
+ "type":"Container",
+ "padding":"small",
+ "items":[
+ {
+ "type":"Image",
+ "id":"action_image",
+ "url":"https://filedepot.blob.core.windows.net/build/pending.png"
+ },
+ {
+ "type":"ColumnSet",
+ "columns":[
+ {
+ "type":"Column",
+ "width":"auto",
+ "items":[
+ {
+ "type":"Image",
+ "url":"https://filedepot.blob.core.windows.net/profile/9.png",
+ "style":"person"
+ }
+ ]
+ },
+ {
+ "type":"Column",
+ "width":"stretch",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"**Miguel Garcia** submitted on 8th May"
+ },
+ {
+ "type":"TextBlock",
+ "text":"Travel & stay expenses for customer visit",
+ "spacing":"none",
+ "size":"small"
+ }
+ ]
+ },
+ {
+ "type":"Column",
+ "width":"auto",
+ "items":[
+ {
+ "type":"TextBlock",
+ "text":"$1179",
+ "size":"medium",
+ "weight":"bolder"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "type":"ActionSet",
+ "id":"expenseActions",
+ "horizontalAlignment":"left",
+ "actions":[
+ {
+ "type":"Action.Http",
+ "method":"post",
+ "url":"{actionUrl}",
+ "title":"Approve",
+ "body":"{\"action\": \"approve\", \"id\": \"ER-321377\", \"comment\":\"{{comment.value}}\", \"actionUrl\": \"{actionUrl}\", \"originator\": \"{originator}\"}"
+ },
+ {
+ "type":"Action.ShowCard",
+ "title":"Decline",
+ "card":{
+ "type":"AdaptiveCard",
+ "body":[
+ {
+ "type":"Input.Text",
+ "id":"comment",
+ "isMultiline":true,
+ "placeholder":"Comment (optional)"
+ }
+ ],
+ "actions":[
+ {
+ "type":"Action.Http",
+ "method":"post",
+ "url":"{actionUrl}",
+ "title":"OK",
+ "body":"{\"action\": \"decline\", \"id\": \"ER-321377\", \"comment\":\"{{comment.value}}\", \"actionUrl\": \"{actionUrl}\", \"originator\": \"{originator}\"}"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
]
- },
- {
- "type": "Container",
- "style": "default",
- "items": [
- {
- "type": "ColumnSet",
- "horizontalAlignment": "center",
- "columns": [
- {
- "width": "48px",
- "verticalContentAlignment": "center",
- "items": [
- {
- "type": "Image",
- "spacing": "large",
- "url": "http://messagecardplayground.azurewebsites.net/assets/TINYPulseQuestionIcon.png",
- "horizontalAlignment": "center"
- }
- ]
- },
- {
- "width": "stretch",
- "verticalContentAlignment": "center",
- "items": [
- {
- "type": "TextBlock",
- "spacing": "large",
- "size": "large",
- "text": "**How likely would you be to refer someone to work here?**",
- "wrap": true
- }
- ]
- }
- ]
- },
- {
- "type": "Input.ChoiceSet",
- "id": "score",
- "placeholder": "Select an option",
- "choices": [
- {
- "title": "1 - Extremely unlikely \"I would physically deter them down to my last breath\"",
- "value": "1"
- },
- {
- "title": "2",
- "value": "2"
- },
- {
- "title": "3",
- "value": "3"
- },
- {
- "title": "4",
- "value": "4"
- },
- {
- "title": "5",
- "value": "5"
- },
- {
- "title": "6",
- "value": "6"
- },
- {
- "title": "7",
- "value": "7"
- },
- {
- "title": "8",
- "value": "8"
- },
- {
- "title": "9",
- "value": "9"
- },
- {
- "title": "10 - Extremely likely (\"It's the best place to work\")",
- "value": "10"
- }
- ]
- },
- {
- "type": "Input.Text",
- "id": "feedback",
- "isMultiline": true,
- "placeholder": "Feel free to elaborate"
- },
- {
- "type": "ActionSet",
- "horizontalAlignment": "center",
- "actions": [
- {
- "type": "Action.Http",
- "url": "{actionUrl}",
- "method": "POST",
- "body": "{\"score\": \"{{score.value}}\", \"feedback\" : \"{{feedback.value}}\"}",
- "title": "Respond anonymously"
- }
- ]
- }
- ]
- },
- {
- "type": "Container",
- "items": [
- {
- "type": "ColumnSet",
- "columns": [
- {
- "width": "stretch",
- "verticalContentAlignment": "center",
- "items": [
- {
- "type": "TextBlock",
- "text": "**Streak:**"
- },
- {
- "type": "TextBlock",
- "spacing": "none",
- "text": "**0** survey(s) in a row"
- }
- ]
- },
- {
- "width": "stretch",
- "verticalContentAlignment": "center",
- "items": [
- {
- "type": "TextBlock",
- "text": "Having trouble?",
- "horizontalAlignment": "right"
- },
- {
- "type": "TextBlock",
- "spacing": "none",
- "text": "[Click here](http://www.tinypulse.com) to go to TINYPulse to respond",
- "horizontalAlignment": "right",
- "wrap": true
- }
- ]
- }
- ]
- }
- ]
- }
- ]
-}
+ }
@@ -259,7 +209,7 @@
var cardTemplate = $("#cardTemplate").html();
- var card = cardTemplate.replace("{actionUrl}", actionUrl).replace("{originator}", originator);
+ var card = cardTemplate.replace(/\{actionUrl\}/g, actionUrl).replace(/\{originator\}/g, originator);
$("#cardContent").val(card);