Skip to content
Permalink
Browse files
Update the template for the cards
  • Loading branch information
tony-zhu committed Jun 13, 2018
1 parent f76074e commit fdd2bc8fa63914910703a34117c3f9d1dabaeb70
Showing with 493 additions and 207 deletions.
  1. +36 −18 action/ActionProcessor.js
  2. +159 −0 action/expense_approved.json
  3. +159 −0 action/expense_declined.json
  4. +1 −1 action/index.js
  5. +138 −188 action/instruction.html
@@ -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)
});
});
}
);
}
}

@@ -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}\"}"
}
]
}
}
]
}
]
}
]
}
]
}
]
}
@@ -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}\"}"
}
]
}
}
]
}
]
}
]
}
]
}
]
}
@@ -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);

0 comments on commit fdd2bc8

Please sign in to comment.