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:

  1. 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.

  2. 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.

  3. Install WhatsApp Media Decrypt: To handle WhatsApp media decryption, follow these steps:

    1. Enter the Docker container using the command:

      docker exec -it --user 0 [CONTAINER_ID] /bin/bash
    2. Install Go language using the command:

      apk add go
    3. Install the WhatsApp Media Decrypt using this command:

      go install github.com/ddz/whatsapp-media-decrypt@latest
    4. Clone the repository using this command:

      git clone https://github.com/ddz/whatsapp-media-decrypt.git
    5. Navigate to the WhatsApp Media Decrypt directory

    6. Build the executable file using this command:

      go build
  4. 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.

  5. 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:

  1. Connecting to WhatsApp:
    Admin Node QR Code

    1. Deploy the WhatsApp admin node (along with the whatsappLink node).

    2. The whatsappLink node will initialize, connect with WhatsApp, and generate a QR code below the Admin Node (in the terminal also).

    3. Scan the QR code with your WhatsApp Mobile App (Go to settings > Linked device > Scan & Connect).

    4. 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:

  1. Mapping Node

  2. Retrieving User List from ERP:

    1. To initiate the mapping process, an "inject" node is scheduled to trigger every five seconds.

    2. When triggered, the "function 1" node sends an HTTP request to the ERP system API using a "GET" method.

    3. 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.

  3. Extracting User Data:

    1. The API response, containing the user list, is received and processed by the "http request" node.

    2. In the subsequent "mapping phone and email" function node, the user list is extracted from the received API payload.

  4. Creating the Mapping:

    1. The function node initializes an empty object named "phoneNumberToEmail" to store the mapping of phone numbers to email addresses.

    2. 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.

  5. Storing the Mapping:

    1. 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.

  1. Mapping Node

  2. Receiving WhatsApp Messages:

    1. 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.

    2. The messages are filtered based on the specified target groups identified by their unique chat IDs. Messages from other groups are discarded.

  3. Extracting Task or Issue Information:

    1. The filtered messages are processed by the "filter group messages" function node to identify whether they pertain to a task or an issue.

    2. The function node splits the received message into words to analyze the last word of the message.

    3. 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.

    4. If the last word is "#issue," the message is identified as an issue, and the subject and description are extracted from the message.

  4. Mapping Phone Number to Email Address:

    1. To ensure effective communication and proper assignment, the assigned_to and assigned_by fields need to be email addresses.

    2. 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.

  5. Preparing the Payload:

    1. For tasks, a new payload is created for the "ToDo" doctype in the ERP system.

    2. The payload includes the email address of the task assignee, the task description, and the reference_type set to "Task."

    3. For issues, a new payload is created for the "Issue" doctype in the ERP system.

    4. The payload includes the subject and description of the issue.

  6. Sending the Payload to ERP:

    1. The created payload for the task or issue is sent to the ERP system using an HTTP POST request.

    2. 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.

    3. The ERP system processes the payload and creates a new task or issue record.

  7. Notifying the Task Assignee:

    1. 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.

    2. The notification message informs the assignee that they have been assigned to a task, along with the task description.

    3. 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.

  1. Mapping Node

  2. Extracting Media URL and Media Key:

    1. 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.

    2. If the message has media, the function node extracts the media URL and media key from the message.

    3. 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.

    4. The message is then passed to the next node to download the media.

  3. Downloading and Decrypting Media:

    1. 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).

    2. 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.

    3. The decrypted media file is stored with a unique filename generated earlier.

  4. Preparing the Payload:

    1. 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.

    2. 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.

    3. The phone number and sender's phone number are mapped to their corresponding email addresses using the "phoneNumberToEmail" mapping stored in the global context.

    4. 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."

    5. If the caption ends with "#issue," the function node extracts the subject and description for the issue.

    6. A new payload is created for the "Issue" doctype in the ERP system, including the subject and description.

  5. Sending the Payload to ERP:

    1. The created payload for the task or issue, along with the media file, is sent to the ERP system using an HTTP POST request.

    2. The media file is uploaded to the ERP system using another HTTP POST request to the "upload_file" API endpoint.

    3. 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.

  1. Mapping Node

  2. Extracting Note Details:

    1. 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

    2. 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.

    3. A new payload for the "Note" doctype in the ERP system is created, including the title and description of the note.

  3. Creating the Note in ERP:

    1. The note payload is sent to the ERP system using an HTTP POST request to the "Note" API endpoint.

    2. The ERP system processes the payload and creates a new note record with the specified title and description.

  4. Sharing the Note Privately:

    1. 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.

    2. 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).

    3. The payload is sent to the ERP system using another HTTP POST request to the "DocShare" API endpoint.

    4. This step ensures that the sender of the note has the appropriate access to view and edit their own note privately.


Next page

Whatsapp-ERP Integration Methods