Skip to content

MerciGlobal Cloud ERP

WhatsApp Chatbot Setup Guide

This document explains the complete end-to-end process for setting up a WhatsApp Chatbot in MerciGlobal Cloud ERP, including webhook registration, template approval, workflow automation, CRM integration, PHP configuration, and licensing.


1. Webhook Registration

Step 1: Register Webhook URL

  1. Navigate to: Channels
  2. Click on Add Webhook
  3. Enter the following URL: https://devx.merciglobal.com/apis/wbot.php

  4. Save the configuration.

Ensure the webhook is properly registered before proceeding to template creation.


2. Template Creation

Two templates must be created:

  1. Template for Non-Customers
  2. Template for Customers

Important Notes:

  • Templates must be approved before usage.
  • Use the Sync and Refresh buttons.
  • Continue refreshing until the template status becomes:
  • Approved
  • Rejected

Only approved templates can be used inside workflows.


3. Create API via Workflow

Navigate to: Menu → Automation → Workflow

Steps:

  1. Click Add
  2. Select Webhook
  3. Choose Custom Webhook
  4. Provide a suitable Title
  5. Click Create
  6. Click Save Webhook
  7. Click Capture Parameters
  8. Copy the generated Webhook URL
  9. Open the generated webhook URL in a new browser tab and append parameters.

Example:

Append to the created webhook: ?mobile=919879000300&msg=Test&file=sample and click enter in the browser tab. You will find Success result.

Check Webhook Parameters captured:

  1. Validate that parameters are correctly received

Ensure parameters such as mobile, msg, file, etc., are detected properly.


4. Connect Workflow to CRM

  1. Connect the created widget on the workflow wall to CRM
  2. From CRM list select: Send Message Template V2
  3. Click Refresh next to Channel selection and select the Channel Name
  4. Click Refresh next to Template selection and select the required approved template

Parameter Mapping

  • Map webhook parameters to template variables.
  • Ensure correct mapping of mobile number and dynamic message parameters.

5. Save and Enable Workflow

  1. Provide a meaningful Title on top corner
  2. Enable the workflow for active usage
  3. Save the workflow

The API is now successfully created for CRM automation.


6. Configure wbot.php File

Copy the sample wbot.php file into your project directory.

Modify the following:

  • Project Name
  • API welcome URLs
  • Campaign values
  • Database logic
  • CRM redirection logic

7. WhatsApp Chatbot License Creation

To activate WhatsApp chatbot usage:

  1. A License for WhatsApp chatbot usage for the project is required to be created
  2. Send the following to Admin:
  3. Customer registration details
  4. Payment confirmation details
  5. Admin will create WhatsApp account access License for the customer project

Chatbot will not function without proper licensing.


Sample wbot.php Code

<?php 

function wbot_process_msg($wbot,$info){ 
   $from = substr($info['from_mobile'],2); 
   $person = $info['person']; 
   $msg = trim($info['message']); 
   $time = date('d M Y') . ' @ ' . date('H:i:s'); 

   $wbot->dolog(json_encode($info)); 

   initProject( 'PROJECT_NAME', 1, 1 ); 

   $yrcompinfo = getYearCompIDCurrentDate(); 
   $yearid = $yrcompinfo['yearid']; 
   $compid = $yrcompinfo['compid']; 

   initProject( 'PROJECT_NAME', $yearid, $compid ); 

   $q = "SELECT id, account 
         FROM #fasmast 
         WHERE mobile LIKE '%$from%' /*AND compid=$compid*/"; 
   $res = myExecute($q); 
   if ($res->num_rows == 0){ 
      $res->close();

      // Message Sender NOT found in records
      $campaign = 'Adhoc'; 
      $url = "API_URL_FROM_ABOVE_SYSTEM_FOR_NON_CUSTOMERS?mobile=91$from";
   }
   else{
      $row = getrow($res); 
      $acid = $row['id']; 
      $name = proper($row['account']); 
      $res->close(); 

      if (at('SAMPLE',$msg) >= 0){ 
         $bal = NetBalance( $acid ) . " (acid=$acid)"; 

         $url = "https://webhooks.whatapi.in/webhook/66fffd6e76f37bade3f747d8?mobile=91$from&   project=cipl&answer=Ledger%20Balance%20$bal"; 
      } 
      else{ 
         // Customer initiated chat
         $crm_tts_code = base64_url_encode("project=cipl&mobile=$from"); 

         $url = $wbot->api_welcome_cust . "?mobile=91$from&url=$crm_tts_code"; 
      }
   } 
   $wbot->send($url); 
}
?>

Operational Best Practices

  • Ensure mobile numbers are stored in consistent format.
  • Always verify template approval status.
  • Test webhook thoroughly before enabling production workflow.
  • Maintain logging using $wbot->dolog() for debugging.
  • Keep project configuration consistent across API calls.

Implementation Checklist

[ ] Webhook Registered
[ ] Templates Created
[ ] Templates Approved
[ ] Workflow Created
[ ] Parameters Mapped
[ ] Workflow Enabled
[ ] wbot.php Updated
[ ] License Created


End of Document