Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. PUT /api/workflows/ed5d5439-3023-4f63-9568-5818d848c9e8 HTTP/1.1
  2. Host: ddflow-api-stable.azurewebsites.net
  3. Content-Type: application/json
  4. Authorization: c51TBISs69
  5. Cache-Control: no-cache
  6.  
  7. {
  8. "Source": "send-email-reminders-2018-04-24_18-10",
  9. "Script": "const co = require('co');\r\n\r\n\/\/ gtodo environment specific?\r\nconst eventGridSecurityInfo = {\r\n\temail: 'test.qa@gmail.com',\r\n\tpassword: '12345678a',\r\n\tbusinessId: 34966,\r\n\tapiKey: 'XCg5xDwMFT'\r\n};\r\n\r\nlet checkStopCondition = (orderWrapper) => {\r\n\ttry {\r\n\t\treturn orderWrapper.order.orderItems.every(function (item) {\r\n\t\t\treturn item.ticket\r\n\t\t\t\t&& item.ticket.ticketFormDataSet\r\n\t\t\t\t&& item.ticket.ticketFormDataSet.formFieldValues\r\n\t\t\t\t&& item.ticket.ticketFormDataSet.formFieldValues.some(function (field) {\r\n\t\t\t\t\treturn field.fieldName === \"Attach flight itinerary\";\r\n\t\t\t\t})\r\n\t\t});\r\n\t}\r\n\tcatch (e) { \/\/ failed to read one of necessary properties\r\n\t\treturn true;\r\n\t}\r\n}\r\n\r\nlet getMinutesFromDays = (daysCount) => {\r\n\treturn daysCount * 1 * 1;\r\n}\r\n\r\nlet getEmail = (orderWrapper, daysLeft) => {\r\n\tvar body = 'Hi ' + orderWrapper.order.buyer.firstName + ',\\n\\n'\r\n\t\t+ 'You are receiving this email because we have not received your flight itinerary your Vollrath University ABC Training Session on ' + orderWrapper.order.event.startsAtFormatted + '. This item is required to reserve your place in this training.\\n\\n'\r\n\t\t+ 'Your deadline is approaching. If you do not provide us with this information in the next ' + daysLeft + ' days, your spot will be released to allow another ABC member to attend this training.\\n\\n'\r\n\t\t+ 'If you have any questions or concerns regarding your flight arrangements, please contact:\\n\\n'\r\n\t\t+ 'Tish Wimmer\\n'\r\n\t\t+ 'Phone: 920.459.5431\\n'\r\n\t\t+ 'Email: tisha.wimmer@vollrathco.com\\n\\n'\r\n\t\t+ 'Sincerely\\n'\r\n\t\t+ '<img style=\\'width:100px\\' src=\\'https:\/\/az503889.vo.msecnd.net\/eventgrid\/content\/custom\/vollrath\/ddflow-email\/signature.png\\'>\\n'\r\n\t\t+ 'Richard Rupp\\n'\r\n\t\t+ 'Corporate Training Manager';\r\n\r\n\tvar recipientEmail = orderWrapper.order.buyer.email;\r\n\r\n\treturn {\r\n\t\t'From': 'test@vollrath.com',\r\n\t\t'To': recipientEmail,\r\n\t\t'Subject': 'Reminder from Vollrath University',\r\n\t\t'Body': body,\r\n\t\t'ReplyTo': 'test@vollrath.com'\r\n\t};\r\n}\r\n\r\n\r\nmodule.exports = {\r\n\tgetRemoteEntity: function (eventPayload) {\r\n\t\treturn {\r\n\t\t\tremoteEntityId: eventPayload.notifications[0].entity.orderId,\r\n\t\t\tremoteEntityType: 'Order'\r\n\t\t};\r\n\t},\r\n\tdefaultStep: 'scheduleFirstEmail',\r\n\tsteps: {\r\n\t\tscheduleFirstEmail: (context, eventPayload) => {\r\n\t\t\t\/\/ gtodo\r\n\t\t\t\/\/return co(function* () {\r\n\t\t\treturn context.workflow.scheduleNextStep('sendFirstEmail', getMinutesFromDays(3));\r\n\t\t\t\/\/});\r\n\t\t},\r\n\t\tsendFirstEmail: (context, eventPayload) => {\r\n\t\t\treturn co(function* () {\r\n\t\t\t\tconst eventGrid = context.connectors.eventGrid;\r\n\t\t\t\tyield eventGrid.authenticate(eventGridSecurityInfo);\r\n\t\t\t\tvar orderWrapper = yield eventGrid.getFromApi('orders\/' + eventPayload.notifications[0].entity.orderId, { loadOptions: 'All' });\r\n\t\t\t\tif (checkStopCondition(orderWrapper)) {\r\n\t\t\t\t\treturn context.workflow.stop();\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar email = getEmail(orderWrapper, 7);\r\n\t\t\t\tyield context.actions.sendEmail(email);\r\n\t\t\t\t\/\/ gtodo pass new event args?\r\n\t\t\t\treturn context.workflow.scheduleNextStep('sendSecondEmail', getMinutesFromDays(2));\r\n\t\t\t});\r\n\t\t},\r\n\t\tsendSecondEmail: (context, eventPayload) => {\r\n\t\t\treturn co(function* () {\r\n\t\t\t\tconst eventGrid = context.connectors.eventGrid;\r\n\t\t\t\tyield eventGrid.authenticate(eventGridSecurityInfo);\r\n\t\t\t\tvar orderWrapper = yield eventGrid.getFromApi('orders\/' + eventPayload.notifications[0].entity.orderId, { loadOptions: 'All' });\r\n\t\t\t\tif (checkStopCondition(orderWrapper)) {\r\n\t\t\t\t\treturn context.workflow.stop();\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar email = getEmail(orderWrapper, 5);\r\n\t\t\t\tyield context.actions.sendEmail(email);\r\n\t\t\t\treturn context.workflow.scheduleNextStep('sendThirdEmail', getMinutesFromDays(2));\r\n\t\t\t});\r\n\t\t},\r\n\t\tsendThirdEmail: (context, eventPayload) => {\r\n\t\t\treturn co(function* () {\r\n\t\t\t\tconst eventGrid = context.connectors.eventGrid;\r\n\t\t\t\tyield eventGrid.authenticate(eventGridSecurityInfo);\r\n\t\t\t\tvar orderWrapper = yield eventGrid.getFromApi('orders\/' + eventPayload.notifications[0].entity.orderId, { loadOptions: 'All' });\r\n\t\t\t\tif (checkStopCondition(orderWrapper)) {\r\n\t\t\t\t\treturn context.workflow.stop();\r\n\t\t\t\t}\r\n\r\n\t\t\t\tvar email = getEmail(orderWrapper, 3);\r\n\t\t\t\tyield context.actions.sendEmail(email);\r\n\r\n\t\t\t\treturn context.workflow.stop();\r\n\t\t\t});\r\n\t\t}\r\n\t}\r\n};"
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement