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
- Navigate to: Channels
- Click on Add Webhook
-
Enter the following URL: https://devx.merciglobal.com/apis/wbot.php
-
Save the configuration.
Ensure the webhook is properly registered before proceeding to template creation.
2. Template Creation
Two templates must be created:
- Template for Non-Customers
- 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:
- Click Add
- Select Webhook
- Choose Custom Webhook
- Provide a suitable Title
- Click Create
- Click Save Webhook
- Click Capture Parameters
- Copy the generated Webhook URL
- 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:
- Validate that parameters are correctly received
Ensure parameters such as mobile, msg, file, etc., are detected properly.
4. Connect Workflow to CRM
- Connect the created widget on the workflow wall to CRM
- From CRM list select: Send Message Template V2
- Click Refresh next to Channel selection and select the Channel Name
- 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
- Provide a meaningful Title on top corner
- Enable the workflow for active usage
- 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:
- A License for WhatsApp chatbot usage for the project is required to be created
- Send the following to Admin:
- Customer registration details
- Payment confirmation details
- 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