Skip to main content

With the advancement of technology and the need for optimized communication in the medical sector, many companies are seeking innovative solutions. One such company is RT Medical Systems, a leader in the medical technology market. This company identified the need for its clients – the hospitals – to have a more agile and direct means of communication. To meet this demand, RT Medical Systems decided to integrate two of the most popular and efficient communication platforms: Slack and WhatsApp. In this post, we will explore how this integration benefited both the company and its clients.

1. Introduction to Slack and WhatsApp Integration

In an era where the digitization of business and the decentralization of work teams are increasingly prominent, the demand for effective and integrated communication grows exponentially. Integrating Slack with WhatsApp is more than an innovation; it’s the answer to optimizing the flow of communication in multifaceted work environments.

 

Why Slack and WhatsApp?

The Choice of WhatsApp

WhatsApp’s popularity on the global scene and its frequent use by healthcare professionals made it an obvious choice for RT Medical Systems. By allowing their clients to open support via WhatsApp, the company shows that it is attentive to trends and ready to adapt to the needs of hospitals.

The Advantages of Slack

On the other hand, Slack offers a collaborative environment for teams, with features that facilitate internal communication and task management. The ability of the RT Medical Systems support team to respond to clients directly through Slack optimizes efficiency and allows for a quicker response.

How Does the Integration Work?

From WhatsApp to Slack

When a hospital sends a support request via WhatsApp, that message is automatically forwarded to Slack. This allows the RT Medical Systems support team to see the request in real time and start working on it immediately.

Integration with Jira Service Desk

Once the request is received on Slack, an SLA ticket is automatically generated in the Jira Service Desk. This ensures that each request is tracked, managed, and resolved in accordance with the agreed-upon service standards.

Integration Functionality

Whatsapp integration in Slack

The proposed integration aims to transform the way teams interact with external contacts in Slack, optimizing the user experience and organizing communication more efficiently.

Single Channel in Slack

In Slack, you will create a channel and designate it specifically for this integration. It’s in this channel that the magic happens. Upon receiving a message from WhatsApp, the integration will format and send the message to this specific channel.

Pre-formatted Message Blocks

Each message that enters the Slack channel is presented in a predefined block format. These blocks serve as a kind of contact card, containing vital contact information such as their photo and phone number. This approach ensures that WhatsApp messages maintain their distinct identity and context in Slack.

Threads for Conversations

To maintain organization and ensure conversations don’t get lost in a sea of messages, each WhatsApp contact card will have its own thread within the channel. This means that when receiving a message from a contact, the integration will look for the corresponding thread of that contact and add the message there. If it’s the first message from that contact, a new thread will be created. This ensures a clear and organized view of all conversations.

Webhooks for Communication

We use webhooks to capture and post messages in Slack. Combined with Slack’s formatting features, these messages are meticulously crafted to visually resemble WhatsApp messages, maintaining consistency and familiarity for users.

 

2. Prerequisites and Initial Setup

Clone the GitHub Repository: RT Medical Systems has made available to the community the first version of the code that does not use the official WhatsApp API. The source code for this integration is available on the healthtech’s GitHub. You can clone it using the following command:

To ensure the effectiveness of this tutorial, it is crucial that the following prerequisites are met:

  • Docker: Provides a consistent execution environment.
  • MongoDB: For persistent data storage.
  • Slack Account: With necessary administrative permissions.

3. Configuration of Environment Variables

Environment variables are essential for the operation and security of the application. The .env file focuses on storing these variables. It should be configured as described:

SLACK_SIGNING_SECRET=
SLACK_TOKEN=
WHATSAPP_PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable
WHATSAPP_CHANNEL_NAME=
PORT=80
SLACK_CHAT_POST_MESSAGE_URL=https://slack.com/api/chat.postMessage
SLACK_WEBHOOK_URL=
SLACK_API_URL=https://slack.com/api/files.upload

4. MongoDB Atlas: Configuration and Free Account Creation

MongoDB Atlas is a fully managed, global cloud database service that is widely used due to its flexibility, scalability, and reliability. For our integration, we will use Atlas, thus ensuring efficient data storage that is accessible from anywhere.

Creating a Free Account on MongoDB Atlas

  1. Visit the Official Website: Go to MongoDB Atlas.
  2. Click on ‘Start Free’: Located in the top right corner of the homepage.
  3. Sign Up: Provide your details such as email, password, and name. After filling out the information, click on “Continue”.
  4. Check Your Email: A confirmation message will be sent to the provided email address. Click on the verification link.
  5. Initial Setup: Once the account is verified, you will be redirected back to MongoDB Atlas. Here, you can set some preferences like project and cluster name. For our tutorial, we can use the free “Shared Clusters” plan.
  6. Cluster Configuration: Choose your preferred cloud provider (AWS, Google Cloud, Azure) and then the region. Keep the default settings for the other options and click on “Create Cluster”.
  7. Connect your Application: After the cluster is created (this might take a few minutes), click on “CONNECT”. Here, you can set up the access IP and create a user to connect to the database. After this setup, select “Connect Your Application”. A connection string that can be used in your application will be provided. This string will look similar to the format:
mongodb+srv://<username>:<password>@cluster-url/test?retryWrites=true&w=majority

Integration with your Application

In the db.js file of your application, use the URI provided by MongoDB Atlas to connect to the database:

const mongoose = require('mongoose');
const uri = 'your_connection_string_here'; // Replace with your URImongoose.connect(uri, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
console.log('Connected to MongoDB Atlas');
}).catch(err => {
console.error('Error connecting to MongoDB Atlas:', err.message);
});

5. Docker: Isolated Runtime Environment

Docker is instrumental in ensuring that the application runs in a uniform environment. The detailed specification for building the environment is contained in the Dockerfile and docker-compose.yml files. Both must be properly configured to ensure the optimized operation of the application.

6. Obtaining Slack Credentials and Permissions

Slack credentials are essential to authenticate and authorize our application to interact with Slack.

  1. Creating a New Slack App: Go to the Slack API and start creating a new app.
  2. App Configuration: Here, details like SLACK_SIGNING_SECRET and SLACK_TOKEN are obtained.

7. Anatomy of the Main Code

The app.js file contains the main code of the application, and examining it provides a clear view of the integration’s operational logic.

The code is structured into various sections:

  • Library Imports: Here, libraries such as express, axios, and dotenv are imported.
const express = require('express');
const axios = require('axios');
const dotenv = require('dotenv');
  • Server Configuration and Routes: The application defines specific routes to interact with Slack and WhatsApp.
  • Message Handling: Here, Slack messages are processed and forwarded to WhatsApp and vice-versa.

8. Running and Monitoring the Application

With everything set up, the application can be started using the command:

docker-compose up

It’s essential to monitor the logs and check if the application is correctly communicating with both platforms.

9. Final Considerations and Best Practices

Completing a successful integration between Slack and WhatsApp requires diligence and attention to detail. Always test in a secure environment before moving to production. Stay updated with the best practices and updates from both platforms.

Leave a Reply