Whatsapp-ERP Integration
Introduction:
This documentation provides an overview of the WhatsApp-ERP Integration implemented using Node-RED. The project aims to integrate WhatsApp messaging with an ERP system, allowing users to create tasks, issues, and notes in the ERP system directly from WhatsApp messages. The integration is facilitated using the Node-RED platform, which provides an intuitive visual programming interface for building complex workflows.
The WhatsApp -ERP Integration streamlines communication and task management processes by enabling seamless interaction between WhatsApp and the ERP system. With this integration, users can easily create and track tasks, report issues, and jot down notes without leaving the WhatsApp interface. This eliminates the need for manual data entry and ensures real-time synchronization of information between the messaging platform and the ERP system.
By leveraging Node-RED's visual programming capabilities, the project offers a user-friendly environment for designing and customizing the integration flow. Various nodes, including message filters, HTTP requests, and debugging tools, are utilized to process incoming WhatsApp messages, extract relevant data, and communicate with the ERP system's API to create records.
The documentation outlines the project's requirements, implementation details, and the step-by-step process of how WhatsApp messages are transformed into tasks, issues, or notes within the ERP system. Additionally, it highlights the user mapping functionality, which associates phone numbers with email addresses for identification purposes, ensuring effective communication within the integrated environment.
Prerequisites:
Before setting up the WhatsApp Integration Project, ensure the following requirements are met:
Install Node-RED: Node-RED must be installed and running on your system. Node-RED provides a flow-based development environment for building event-driven applications.
Install node-red-contrib-whatsapp-link Palette: Install the "node-red-contrib-whatsapp-link" palette in Node-RED. This palette allows you to integrate WhatsApp messaging into your flows. You can find the palette at: node-red-contrib-whatsapp-link.
Install WhatsApp Media Decrypt: To handle WhatsApp media decryption, follow these steps:
Enter the Docker container using the command:
docker exec -it --user 0 [CONTAINER_ID] /bin/bash
Install Go language using the command:
apk add go
Install the WhatsApp Media Decrypt using this command:
go install github.com/ddz/whatsapp-media-decrypt@latest
Clone the repository using this command:
git clone https://github.com/ddz/whatsapp-media-decrypt.git
Navigate to the WhatsApp Media Decrypt directory
Build the executable file using this command:
go build
ERP API Access: Obtain access to your ERP system's API documentation and credentials. This is essential for integrating Node-RED with the ERP system to create tasks, issues, and notes programmatically.
Optional: Install node-red-contrib-image-output Palette: If you wish to utilize image output functionality, you can install the "node-red-contrib-image-output" palette. This palette allows you to display images in the Node-RED dashboard. You can find it at: node-red-contrib-image-output.
Process/Flow of the Integration
Setting up Admin Node for WhatsApp Integration:
To set up the Admin Node for the WhatsApp Integration Project using Node-RED, follow these steps:
Connecting to WhatsApp:
Deploy the WhatsApp admin node (along with the whatsappLink node).
The whatsappLink node will initialize, connect with WhatsApp, and generate a QR code below the Admin Node (in the terminal also).
Scan the QR code with your WhatsApp Mobile App (Go to settings > Linked device > Scan & Connect).
Done - WhatsApp Connected.
Mapping Phone Numbers with Email Addresses:
The process of mapping phone numbers with email addresses is a crucial step in the WhatsApp - ERP Integration. It enables effective communication and identification of users within the integrated environment. Below is the descriptive process of how phone numbers are associated with email addresses:
Retrieving User List from ERP:
To initiate the mapping process, an "inject" node is scheduled to trigger every five seconds.
When triggered, the "function 1" node sends an HTTP request to the ERP system API using a "GET" method.
The API endpoint "loranet_technologies.get_user_list" is accessed to retrieve the user list data containing information such as phone numbers and email addresses.
Extracting User Data:
The API response, containing the user list, is received and processed by the "http request" node.
In the subsequent "mapping phone and email" function node, the user list is extracted from the received API payload.
Creating the Mapping:
The function node initializes an empty object named "phoneNumberToEmail" to store the mapping of phone numbers to email addresses.
A loop iterates through each user in the user list, and for each user:
The user's phone number is prefixed with "@" and "6" to match the existing phone number format used in the flow. (Note: The specific formatting may vary based on requirements.)
The user's email address is retrieved.
If both the phone number and email address are available for the user, a mapping entry is created in the "phoneNumberToEmail" object, associating the phone number with the email address.
Storing the Mapping:
The completed "phoneNumberToEmail" object, containing all the mapped phone numbers and email addresses, is stored in the global context using the "global.set()" function. This ensures that the mapping is accessible across the entire flow.
Assigning Tasks or Raising Issues from WhatsApp:
The process of assigning tasks or raising issues from WhatsApp is a key functionality of the WhatsApp Integration Project. It allows users to create tasks or report issues directly from the WhatsApp interface, which are then seamlessly processed and recorded in the ERP system.
Receiving WhatsApp Messages:
WhatsApp messages are received through the "Chats In" node, which is connected to the WhatsApp platform using the "whatsappLink" configured with the "whatsapp-web" client type.
The messages are filtered based on the specified target groups identified by their unique chat IDs. Messages from other groups are discarded.
Extracting Task or Issue Information:
The filtered messages are processed by the "filter group messages" function node to identify whether they pertain to a task or an issue.
The function node splits the received message into words to analyze the last word of the message.
If the last word is "#task," the message is identified as a task, and relevant information such as the phone number, task description, and sender's phone number (assigned_by) are extracted.
If the last word is "#issue," the message is identified as an issue, and the subject and description are extracted from the message.
Mapping Phone Number to Email Address:
To ensure effective communication and proper assignment, the assigned_to and assigned_by fields need to be email addresses.
The phone number extracted from the message (assigned_to) and the sender's phone number (assigned_by) are mapped to their corresponding email addresses using the "phoneNumberToEmail" mapping stored in the global context.
Preparing the Payload:
For tasks, a new payload is created for the "ToDo" doctype in the ERP system.
The payload includes the email address of the task assignee, the task description, and the reference_type set to "Task."
For issues, a new payload is created for the "Issue" doctype in the ERP system.
The payload includes the subject and description of the issue.
Sending the Payload to ERP:
The created payload for the task or issue is sent to the ERP system using an HTTP POST request.
The request is made to the appropriate API endpoint in the ERP system based on the "requestUrl" determined in the "filter group messages" function node.
The ERP system processes the payload and creates a new task or issue record.
Notifying the Task Assignee:
If the message was identified as a task (#task) and the assignee's phone number is available (msg.toNumber is not null), the "Send to Task Assignee" function node generates a notification message.
The notification message informs the assignee that they have been assigned to a task, along with the task description.
The notification message is sent back to WhatsApp through the "Chats Out" node, connected to the WhatsApp platform using the "whatsappLink" configured with the "whatsapp-web" client type.
Assigning Tasks or Raising Issues with Media from WhatsApp:
The process of assigning tasks or raising issues with media from WhatsApp enhances the functionality of the WhatsApp Integration Project, allowing users to create tasks or report issues along with media attachments directly from the WhatsApp interface. This process provides a seamless integration with the ERP system, enabling users to efficiently communicate and track tasks or issues that require media content.
Extracting Media URL and Media Key:
The filtered messages are processed by the "get img url" function node to check if they contain media attachments (images, videos, or documents) and a caption.
If the message has media, the function node extracts the media URL and media key from the message.
The media URL is stored in the message object, and a unique filename is generated for the media based on the current date and time.
The message is then passed to the next node to download the media.
Downloading and Decrypting Media:
The message containing the media URL and media key is passed to the "Download .enc file" node, which uses the "wget" command to download the encrypted media file (.enc).
After downloading the .enc file, it is passed to the "decrypt whatsapp image" node, which uses an external utility (whatsapp-media-decrypt) to decrypt the media file.
The decrypted media file is stored with a unique filename generated earlier.
Preparing the Payload:
The message containing the decrypted media is passed to the "Task or issue with media" function node to determine whether it is a task or an issue based on the caption of the media.
If the caption ends with "#task," the function node extracts the phone number, task description, and sender's phone number (assigned_by) from the caption.
The phone number and sender's phone number are mapped to their corresponding email addresses using the "phoneNumberToEmail" mapping stored in the global context.
A new payload is created for the "ToDo" doctype in the ERP system, including the email address of the task assignee, the task description, and the reference_type set to "Task."
If the caption ends with "#issue," the function node extracts the subject and description for the issue.
A new payload is created for the "Issue" doctype in the ERP system, including the subject and description.
Sending the Payload to ERP:
The created payload for the task or issue, along with the media file, is sent to the ERP system using an HTTP POST request.
The media file is uploaded to the ERP system using another HTTP POST request to the "upload_file" API endpoint.
The ERP system processes the payloads and creates a new task or issue record along with the attached media.
Taking Notes from WhatsApp:
The process of taking notes from WhatsApp streamlines the note-taking experience for users by allowing them to create notes directly from the WhatsApp interface. This process leverages the WhatsApp Integration Project to facilitate the seamless creation and storage of notes in the ERP system.
Extracting Note Details:
The message is passed to the "Task, Issue, and Note" function node, which checks if the last word in the message is "#task" or "#issue" or else
If the last word is other than "#task" or "#issue", the function node extracts the title and description of the note from the message payload.
A new payload for the "Note" doctype in the ERP system is created, including the title and description of the note.
Creating the Note in ERP:
The note payload is sent to the ERP system using an HTTP POST request to the "Note" API endpoint.
The ERP system processes the payload and creates a new note record with the specified title and description.
Sharing the Note Privately:
After creating the note, the "Share the private document to the sender" function node prepares a payload for the "DocShare" doctype in the ERP system.
The payload includes the user (sender's) email address, the share_doctype set to "Note," the share_name set to the title of the note, and read and write permissions set to 1 (allowing the sender to read and write the note).
The payload is sent to the ERP system using another HTTP POST request to the "DocShare" API endpoint.
This step ensures that the sender of the note has the appropriate access to view and edit their own note privately.
Next page