A simple nodejs script to send text messages to the user using Gupshup's whatsapp service.
Before you start the project, make sure you have the gupshup whatsapp account set up. You can use this link to sign in: https://www.gupshup.io/developer/home.
Once you have the gupshup whatsapp account set up, enter the API_KEY, APP_NAME and SOURCE_MOBILE_NUMBER in .env file. If using the test account, then SOURCE_MOBILE_NUMBER would be 917834811114
.
Once set up is done. Run the following command to start the server.
npm install
npm start
The server will run on port 3000.
There are a limited set of APIs that are covered compared to gupshup developer documentation. The following are the apis covered in this express app.
Api to get the list of templates available.
- Type: 'GET'
- Response OK Status: 200
Api to mark user opt in for sending the whatsapp message.
- Type: 'GET'
- Content Type: 'application/json'
- Params:
- mobileNumber: string
- Response OK Status: 200
Api to send image along with the caption.
- Type: 'GET'
- Content Type: 'application/json'
- Params:
- mobileNumber: string
- imageUrl: string(public available image url)
- caption: string
- Response OK Status: 200
Api to send video along with the caption.
- Type: 'GET'
- Content Type: 'application/json'
- Params:
- mobileNumber: string
- videoUrl: string(public available video url)
- caption: string
- Response OK Status: 200
Api to send text message.
- Type: 'GET'
- Content Type: 'application/json'
- Params:
- mobileNumber: string
- message: string(4096 characters limit)
- Response OK Status: 200
Api to send templated text message.
- Type: 'GET'
- Content Type: 'application/json'
- Params:
- mobileNumber: string
- templateId: string
- templateParams: array of string containing data for each param
- message: string(4096 characters limit)/object
- Response OK Status: 200
refer this link to see what params to send in message
and template params
: https://www.gupshup.io/developer/docs/bot-platform/guide/whatsapp-api-documentation#templateOutboundMessage
Before you run the script, make sure that you have the user details in csv format having first column to be name and other column to be mobileNumber. You can take at the example file in assets folder(/assets/usersDetails.csv)
To run the script, type
node run bulkOptIn
The output of the script file will be stored in results/bulkOptInResults.json file.
To run the script, type
node run bulkSend
The output of the script file will be stored in results/bulkSendResults.json file.