📁 Showcase
Automation

Automation

1. AutomateWhatsAppInvoice

a. Variables

Create the message variables for the MessageSendOnWhatsapps automation step, VarWhatsappMessage1, VarWhatsappMessage2, and VarWhatsappMessage3

ensure var VarWhatsappMessage1 kind: text 
  deploy: fixedOnDeploy 
  value: "Hello ${Customer},"
ensure var VarWhatsappMessage2 kind: text 
  deploy: fixedOnDeploy 
  value: "Here is your invoice dated ${Date}, with total ${Amount}."
ensure var VarWhatsappMessage3 kind: text 
  deploy: fixedOnDeploy 
  value: "Payment link: ${PaymentLink}"

Create a VarInvoicePdfName variable that works as pdf name for the GenerateInvoicePdf step.

ensure var VarInvoicePdfName kind: text 
  deploy: fixedOnDeploy 
  value: "Invoice"

Create a VarMappingGenerateInvoiceDeeplink variable to map data between the source and target forms in the GenerateInvoiceDeeplink automation step.

ensure var VarMappingGenerateInvoiceDeeplink kind: mapping
  deploy: fixedOnDeploy
  fromForm: OutputInvoice
  toForm: FilterInvoice
  fieldMappingMap: {
    'map': {
      '${f:FromDate}': 'FromDate',
      '${f:ToDate}': 'ToDate',
      '${f:OfficeName}': 'Name',
      '${f:OfficeRowId}': 'OfficeMasterRowId'
    }
  }

b. Automation

Set up an AutomateInvoiceCache automation for the InvoiceHistory spreadsheet.

ensure automation AutomateInvoiceCache kind: spreadsheet
  spreadsheet: InvoiceHistory

Add a BeforeInsert event to the AutomateInvoiceCache automation.

// before insert event
ensure event BeforeInsert fire: beforeInsert

Add a GenerateInvoiceDeeplink step to the BeforeInsert event to create the deeplink for the OutputInvoice form using the provided order values.

// deeplink generate step for invoice
ensure step GenerateInvoiceDeeplink kind: generateDeeplink
  deeplink: DeeplinkGetInvoice
  deeplinkField: InvoiceLink
  inputFormMappingVar: VarMappingGenerateInvoiceDeeplink

Add a GeneratePaymentLink step to the BeforeInsert event to produce a payment link for the customer, enabling them to settle the invoice amount.

// payment link generate for invoice
ensure step GeneratePaymentLink kind: generatePaymentLink 
  allowedPaymentMethodSet: ["upi"] 
  referenceIdField: Details.InvoiceId 
  spreadsheetRowIdField: $RowId 
  paymentLinkField: Summary.PaymentLink
  currencyValue: "${constant:currency.INR}" 
  amountValue: "${f:Summary.GrandTotal}"
  expiryDurationValue: "${constant:duration.30 days}"

Add a GenerateInvoicePdf step to the BeforeInsert event to produce an invoice pdf.

// pdf generate for invoice
ensure step GenerateInvoicePdf kind: generatePdf 
  pdfField: Summary.InvoicePdf
  contentLayout: FlexMain
  templateLayout: Template
  fileNameVar: {
      'var': 'VarInvoicePdfName'
    }

Add an AfterInsert event to the AutomateInvoiceCache automation.

// after insert event
ensure event AfterInsert fire: afterInsert

Add a MessageSendOnWhatsapp step to the AfterInsert event to send a WhatsApp message when the invoice is generated.

// message send on WhatsApp
ensure step MessageSendOnWhatsapp kind: sendWhatsappTemplateMessage
  dataSourceField: Details.Mobile 
  mediaField: Summary.InvoicePdf 
  templateGroupId: "36ab8ba797dc5cba4ec7e0b040ee8591"
  messageVarMap: [
      "{
        'var': 'VarWhatsappMessage1',
        'paramSet': [
          '${f:Details.OfficeName}'
        ]
      }",
      "{
        'var': 'VarWhatsappMessage2',
        'paramSet': [
          '${f:Details.InvoiceDate}',
          '${f:Summary.GrandTotal}'
        ]
      }",
      "{
        'var': 'VarWhatsappMessage3',
        'paramSet': [
          '${f:Summary.PaymentLink}'
        ]
      }"
    ]

2. WebhookRazorpayPayment

a. Variables

Create a VarMappingPaymentUpdateInvoiceSheet variable to map data between the source and target forms in the UpdateSpreadsheet automation step.

ensure var VarMappingPaymentUpdateInvoiceSheet kind: mapping
  deploy: fixedOnDeploy
  toForm: OutputInvoice
  fieldMappingMap: {
    'map': {
      '${d:PaymentStatus.paid}': 'Summary.PaymentStatus'
    }
  }

b. Automation

Set up a WebhookRazorpayPayment automation.

ensure automation WebhookRazorpayPayment kind: webhook
  callbackKind: razorpayPaymentReceipt

Add an OnCallback event to the WebhookRazorpayPayment automation.

// on callBack  event
ensure event OnCallback fire: onCallback

Add an UpdateSpreadsheet step to the OnCallback event to update the payment status.

// update spreadsheet
ensure step UpdateSpreadsheet kind: updateSpreadsheet
  targetSpreadsheet: InvoiceHistory
  rowIdField: SpreadsheetRowId
  sourceToTargetMappingVar: VarMappingPaymentUpdateInvoiceSheet