├── README.md
├── config.js
├── files
├── file-example_PDF_500_kB.pdf
├── file_example_JPG_100kB.jpg
├── file_example_MP3_1MG.mp3
├── file_example_MP4_480_1_5MG.mp4
├── sample-vcard.txt
└── webhook_example.json
├── index.js
├── package.json
└── whapi.d.ts
/README.md:
--------------------------------------------------------------------------------
1 | # Free WhatsApp NodeJS Bot (Whapi.Cloud WhatsApp API)
2 | This example of the WhatsApp bot implementation touches in detail on the most frequently used functionality: send message, send file, create group, send message to WhatsApp Group. This will allow you to adapt WhatsApp API and source code to your tasks and needs, or take it as a basis for creating any other integration.
3 | In the source code of the bot you will find the following functionality:
4 |
5 |
Send regular text message;
6 |
Send media: image / file / video;
7 |
Send contact (vCard);
8 |
Send product;
9 |
Create new group, send an invitation and send message to the group;
10 |
Receive and reading incoming messages;
11 |
Respond to an unfamiliar command, this could be an instruction or your welcome message;
12 |
13 |
14 | You will be able to use our source code in your project, easily modifying and supplementing the script's functionality. Based on the code, you can create your chatbot or any integration. Easily integrate it into existing workflows, continuing to use WhatsApp as usual!
15 |
16 | ### Step-by-step instructions on how to set up and run this chatbot: https://whapi.cloud/setting-up-chatbot-whatsapp-nodejs
17 | We'll talk in detail about how to test the bot on a local, which servers to use, some tips and the main causes of popular failures.
18 |
--------------------------------------------------------------------------------
/config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | // API endpoint URL
3 | apiUrl: "https://gate.whapi.cloud",
4 | // API token from your channel
5 | token: "YOUR CHANNEL TOKEN",
6 | // The ID of the group to which we will send the message. Use to find out the ID: https://whapi.readme.io/reference/getgroups
7 | group: '120363167596599603@g.us',
8 | // The ID of the product we will send for the example. Create a product in your WhatsApp and find out the product ID: https://whapi.readme.io/reference/getproducts
9 | product: '6559353560856703',
10 | // Bot`s URL (for static file). Webhook Link to your server. At ( {server link}/hook ), when POST is requested, processing occurs
11 | botUrl: "https://yoursite.com/hook",
12 | // Bot's Port (for hook handler). Don't use 443 port.
13 | port: "80"
14 | }
15 |
--------------------------------------------------------------------------------
/files/file-example_PDF_500_kB.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Whapi-Cloud/nodejs-whatsapp-chatbot/bbb7c697ef2c0b34cf9e81a430b3075a5b2cc9d9/files/file-example_PDF_500_kB.pdf
--------------------------------------------------------------------------------
/files/file_example_JPG_100kB.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Whapi-Cloud/nodejs-whatsapp-chatbot/bbb7c697ef2c0b34cf9e81a430b3075a5b2cc9d9/files/file_example_JPG_100kB.jpg
--------------------------------------------------------------------------------
/files/file_example_MP3_1MG.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Whapi-Cloud/nodejs-whatsapp-chatbot/bbb7c697ef2c0b34cf9e81a430b3075a5b2cc9d9/files/file_example_MP3_1MG.mp3
--------------------------------------------------------------------------------
/files/file_example_MP4_480_1_5MG.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Whapi-Cloud/nodejs-whatsapp-chatbot/bbb7c697ef2c0b34cf9e81a430b3075a5b2cc9d9/files/file_example_MP4_480_1_5MG.mp4
--------------------------------------------------------------------------------
/files/sample-vcard.txt:
--------------------------------------------------------------------------------
1 | BEGIN:VCARD
2 | VERSION:3.0
3 | N:Gump;Forrest;;Mr.;
4 | FN:Forrest Gump
5 | ORG:Bubba Gump Shrimp Co.
6 | TITLE:Shrimp Man
7 | TEL;TYPE=WORK,VOICE:(111) 555-1212
8 | TEL;TYPE=HOME,VOICE:(404) 555-1212
9 | ADR;TYPE=WORK,PREF:;;100 Waters Edge;Baytown;LA;30314;United States of America
10 | LABEL;TYPE=WORK,PREF:100 Waters Edge\nBaytown\, LA 30314\nUnited States of America
11 | ADR;TYPE=HOME:;;42 Plantation St.;Baytown;LA;30314;United States of America
12 | LABEL;TYPE=HOME:42 Plantation St.\nBaytown\, LA 30314\nUnited States of America
13 | EMAIL:forrestgump@example.com
14 | REV:2008-04-24T19:52:43Z
15 | END:VCARD
16 |
--------------------------------------------------------------------------------
/files/webhook_example.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Whapi-Cloud/nodejs-whatsapp-chatbot/bbb7c697ef2c0b34cf9e81a430b3075a5b2cc9d9/files/webhook_example.json
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const bodyParser = require('body-parser');
3 | const fs = require('fs');
4 | const fetch = require('node-fetch');
5 | const FormData = require('form-data');
6 | const config = require('./config.js');
7 |
8 | process.on('unhandledRejection', err => {
9 | console.log(err)
10 | });
11 |
12 | const COMMANDS = { // bot commands
13 | TEXT: 'Simple text message',
14 | IMAGE: 'Send image',
15 | DOCUMENT: 'Send document',
16 | VIDEO: 'Send video',
17 | CONTACT: 'Send contact',
18 | PRODUCT: 'Send product',
19 | GROUP_CREATE: 'Create group',
20 | GROUP_TEXT: 'Simple text message for the group',
21 | GROUPS_IDS: 'Get the id\'s of your three groups'
22 | }
23 |
24 | const FILES = { // file path
25 | IMAGE: './files/file_example_JPG_100kB.jpg',
26 | DOCUMENT: './files/file-example_PDF_500_kB.pdf',
27 | VIDEO: './files/file_example_MP4_480_1_5MG.mp4',
28 | VCARD: './files/sample-vcard.txt'
29 | }
30 |
31 | /**
32 | * Send request to Whapi.Cloud
33 | * @param endpoint - endpoint path
34 | * @param params - request body
35 | * @param method - GET, POST, PATCH, DELETE
36 | * @returns {Promise