{"flow":{"id":34,"summary":"Send welcome e-mail to new user and follow up with a delay","versions":[146,150],"created_by":"adam186","created_at":"2022-12-28T16:26:25.650Z","votes":0,"approved":true,"apps":["sendgrid"],"value":{"modules":[{"id":"h","value":{"lock":"","path":null,"type":"rawscript","content":"export async function main(user_name: string, company_name: string, company_email: string) {\n  return {\n    subject: `Welcome to ${company_name}!`,\n    message: `Dear ${user_name},\nThank you for signing up for our application! We are excited to have you as a new user and are looking forward to helping you make the most of our platform.\n\nIf you have any questions or need assistance getting started, please don't hesitate to reach out to us at ${company_email}.\nWe are here to help you get the most out of your experience with our application.\n\nThank you again for choosing us and we hope that you will continue to find value in our platform.\n\nBest regards,\n${company_name}`\n  }\n}","language":"deno","input_transforms":{"user_name":{"expr":"`${flow_input.user_name}`","type":"javascript"},"company_name":{"type":"static","value":""},"company_email":{"type":"static","value":""}}},"summary":"Create welcome email","stop_after_if":null,"input_transforms":{}},{"id":"a","sleep":{"expr":"result","type":"javascript"},"value":{"lock":"","path":"hub/367/sendgrid/send_email_single_recipient","type":"rawscript","content":"import * as wmill from \"https://deno.land/x/windmill@v1.51.0/mod.ts\"\nimport sendgrid from \"npm:@sendgrid/mail@^7.7.0\"\n\nexport async function main(\n  api_token: wmill.Resource<\"sendgrid\">,\n  from: string,\n  to: string,\n  subject: string,\n  message: string,\n  is_message_html: boolean,\n  delay: number\n) {\n  sendgrid.setApiKey(api_token.token);\n  const messageObject: Record<string, string> = { to, from, subject }\n  messageObject[is_message_html ? 'html' : 'text'] = message\n\n  try {\n    await sendgrid.send(messageObject)\n    return delay\n  } catch (error) {\n    throw Error('\\n' + (JSON.stringify(error?.response?.body || error)))\n  }\n}\n","language":"deno","input_transforms":{"to":{"expr":"`${flow_input.user_email}`","type":"javascript"},"from":{"type":"static","value":""},"delay":{"expr":"","type":"javascript"},"message":{"expr":"`${results.h.message}`","type":"javascript"},"subject":{"expr":"`${results.h.subject}`","type":"javascript"},"api_token":{"expr":"","type":"javascript"},"is_message_html":{"type":"static","value":false}}},"summary":"Send welcome email","stop_after_if":null,"input_transforms":{}},{"id":"c","value":{"lock":"","path":null,"type":"rawscript","content":"export async function main() {\n  // Dummy data. Replace this with a call to your backend \n  // or run a query on your database directly.\n  // Don't forget to update the predicate logic on the branching.\n  return Date.now() % 2\n}","language":"deno","input_transforms":{}},"summary":"Get user activity","stop_after_if":null,"input_transforms":{}},{"id":"i","value":{"type":"branchone","default":[{"id":"j","value":{"lock":null,"path":null,"type":"rawscript","content":"export async function main(user_name: string, company_name: string, company_email: string) {\n  return {\n    subject: `Hope you enjoy using ${company_name}!`,\n    message: `Dear ${user_name},\n\nI hope this email finds you well. We just wanted to follow up on your experience with our application so far and see if there is anything we can do to help you get started.\n\nWe noticed that you have not taken any actions within the platform since signing up. If you are having trouble getting started or have any questions about how to use the features, please don't hesitate to reach out to us at ${company_email}. We are here to help and want to ensure that you are getting the most out of your experience with our application.\n\nThank you again for signing up and we hope to see you become an active user of our platform.\n\nBest regards,\n${company_name}`\n  }\n}","language":"deno","input_transforms":{"user_name":{"expr":"`${flow_input.user_name}`","type":"javascript","value":"${flow_input.user_name}"},"company_name":{"expr":"`${results.l.company_name}`","type":"static","value":""},"company_email":{"expr":"`${results.l.company_email}`","type":"static","value":""}}},"summary":"Create 'no-action' follow up email","stop_after_if":null,"input_transforms":{}}],"branches":[{"expr":"results.c > 0","modules":[{"id":"k","value":{"lock":null,"path":null,"type":"rawscript","content":"export async function main(user_name: string, company_name: string, company_email: string) {\n  return {\n    subject: `Hope you enjoy using ${company_name}!`,\n    message: `Dear ${user_name},\n\nI hope this email finds you well. I just wanted to follow up on your experience with our application so far.\n\nIt's great to see that you have been exploring a lot of the features of the platform. We hope that you are finding it useful and that it is helping you achieve your goals.\n\nIf you have any feedback or suggestions on how we can improve your experience, please don't hesitate to let us know by dropping an email to ${company_email}. We value your input and are always looking for ways to improve our product.\n\nThank you again for choosing us and we look forward to continuing to have you on our platform.\n\nBest regards,\n${company_name}`\n  }\n}","language":"deno","input_transforms":{"user_name":{"expr":"`${flow_input.user_name}`","type":"javascript","value":"${flow_input.user_name}"},"company_name":{"expr":"`${results.l.company_name}`","type":"static","value":""},"company_email":{"expr":"`${results.l.company_email}`","type":"static","value":""}}},"summary":"Create 'many-actions' follow up email","stop_after_if":null,"input_transforms":{}}],"summary":"Many actions"}]},"summary":"","stop_after_if":null,"input_transforms":{}},{"id":"g","value":{"lock":"","path":"hub/367/sendgrid/send_email_single_recipient","type":"rawscript","content":"import * as wmill from \"https://deno.land/x/windmill@v1.51.0/mod.ts\"\nimport sendgrid from \"npm:@sendgrid/mail@^7.7.0\"\n\n/** \n * @param is_message_html If `true` then the message will be sent and parsed as HTML, \n * otherwise it will be sent as plain text.\n */\nexport async function main(\n  api_token: wmill.Resource<\"sendgrid\">,\n  from: string,\n  to: string,\n  subject: string,\n  message: string,\n  is_message_html: boolean\n) {\n  sendgrid.setApiKey(api_token.token);\n  const messageObject: Record<string, string> = { to, from, subject }\n  messageObject[is_message_html ? 'html' : 'text'] = message.trim()\n\n  try {\n    return await sendgrid.send(messageObject)\n  } catch (error) {\n    throw Error('\\n' + (JSON.stringify(error?.response?.body || error)))\n  }\n}\n","language":"deno","input_transforms":{"to":{"expr":"`${flow_input.user_email}`","type":"javascript"},"from":{"type":"static","value":""},"message":{"expr":"`${results.i.message}`","type":"javascript"},"subject":{"expr":"`${results.i.subject}`","type":"javascript"},"api_token":{"expr":"","type":"javascript"},"is_message_html":{"type":"static","value":false}}},"summary":"Send follow up e-mail","stop_after_if":null,"input_transforms":{}}],"failure_module":null},"schema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["user_name","user_email"],"properties":{"user_name":{"type":"string","format":"","default":"","description":"Name of the newly signed up user."},"user_email":{"type":"string","format":"","default":"","description":"Email address of the newly signed up user."}}},"description":"Send a welcome e-mail immediately after someone signs up and then send a follow up email based on whether they started using the product or not.","recording":null,"vcreated_at":"2022-12-30T13:06:02.167Z","vcreated_by":"adam186","comments":[]}}