npm install npm install nodemon
You will need
- Your WABA phone number that has been approved by tyntec
- A phone with WhatsApp as a testing customer
- Your tyntec API key from your tyntec account
- A Slack workspace
- Node.js and your favourite text editor or IDE with JavaScript highlighting
- MongoDB installed locally for development
- A ngrok account and the binary installed for development
- Postman
Step One: Get your integration app ready
For your quick start with integrations, we’ve prepared a sample integration app. Let’s look at what the code does. Notice these important pieces of the code:
- /routes handle callback endpoints, which are:
- /tyntec/forwardWAMessage, which receives WhatsApp messages from tyntec and sends them to the Slack API.
- /slack/, which handles slash commands.
- /slack/forwardSlackMessage, which receives messages from Slack and calls tyntec’s Conversations API to send them to WhatsApp.
- /models contain database schemas.
- server.js does basic management and binds the logic together.
Let’s just quickly get your app running:
1. Clone the api-samples repository and go to the wa-integrations/slack folder.
2. Install dependencies (and the nodemon module if you don’t have it yet):
ngrok http 3000
4. Copy .env-example to .env and set environment variables in .env:
- WABA_NUMBER -- your WABA number in the international format without the leading +/00
- TYNTEC_API_KEY -- your API key from tyntec to authenticate calls to Conversations API
- SLACK_BOT_TOKEN -- you’ll set this one later
- MONGO_URL -- optional MongoDB location (defaults to the local instance mongodb://127.0.0.1:27017/tyntec)
- PORT -- optional server port (defaults to 3000)
5. And finally, start the app in another terminal:
nodemon server.js
Step Two: Subscribe your webhook in tyntec
Let tyntec know where to deliver WhatsApp messages from customers. You’re going to subscribe your webhook via an API call in Postman.
1. Download our Postman collection, unpack and import it in Postman.
2. Right-click the collection and select Edit.
3. Go to Variables and set the apikey value to your tyntec API key.
4. Go back to your collection and in the folder Application Management open the patch Update default application (see the reference for details).
5. Edit the Body to update the callbackUrl with your webhook for the MoMessage event. The request body should look like this:
{ "webhooks": [{ "events": [ "MoMessage" ], "callbackUrl": "https://<YOUR_SERVER>/tyntec/forwardWAMessage" }] }

Step Three: Configure Slack
Let’s connect your app with Slack. You are going to create an app, subscribe your webhooks through it, set scopes of permissions for it, install it in your Slack workspace, and finally add it to the channel. Phew, let’s do it!
1. Create a Slack app.
Go to http://api.slack.com > Your apps and hit the Create add App button.
Enter a name for your app and select a Slack workspace.

You may add a logo and set a color for your app in Basic Information > Display Information.
2. Define a slash command, which will help you to manage the connectivity of your app through a channel (such as initiating it).
Go to [Features] Slash Commands > Create New Command.
- Command: /whatsapp
- Request URL: https://<YOUR_SERVER>/slack/
- You may add a description and usage hint.
And Save the command.

Slack adds a bot user for you automatically. You may beautify its display name in [Features] App Home.
3. Subscribe your second Slack webhook to events. Go to [Features] Event Subscriptions, switch on Enable events, and enter your Request URL for message events subscription:
https://<YOUR_SERVER>/slack/forwardSlackMessage
Slack should verify your Request URL and display Verified next to it to acknowledge that as shown below. (Your app must be running for this to happen.)




rs

/whatsapp




/whatsapp close Customer Name
More?
You may, for example, post the message as a new thread after 24 hours since the last customer message automatically. This would require adding a timestamp of the last customer message to the models/contacts.js database schema and extending the function that handles the endpoint /tyntec/forwardWAMessages with a check of the time difference.
Or you could extend your slash commands to send template messages, let’s say something like this:
/whatsapp send "Customer Name" appointment_confirmation "April 1" "8:00 AM"