wapi-custom-notifier allows us to send whatsapp notifications to contacts and group using api calls but without the need to use the official whatsapp cloud api
MIT License
whatsapp-api is a REST API wrapper for the whatsapp-web.js library, providing an easy-to-use interface to interact with the WhatsApp Web platform. It is designed to be used as a docker container, scalable, secure, and easy to integrate with other non-NodeJs projects.
wapi-custom-notifier is a Homeassistant custom notification component that enables us to send notification to Whatsapp groups using the whatsapp-api gateway and without the need to register to 3rd party integrator or the official Whatsapp cloud API.
version: '3.8'
services:
app:
container_name: whatsapp_web_api
image: chrishubert/whatsapp-web-api:latest # Pull the image from Docker Hub
# restart: always
ports:
- "3000:3000"
environment:
#- API_KEY= #Optional - Recomended to enable when goint to prod
- BASE_WEBHOOK_URL=http://localhost:3000/localCallbackExample
- ENABLE_LOCAL_CALLBACK_EXAMPLE=TRUE # OPTIONAL, NOT RECOMMENDED TO ENABLE FOR PRODUCTION. Remove after QR scan
- MAX_ATTACHMENT_SIZE=5000000 # IN BYTES
- SET_MESSAGES_AS_SEEN=FALSE # WILL NOT MARK THE MESSAGES AS READ AUTOMATICALLY
# ALL CALLBACKS: auth_failure|authenticated|call|change_state|disconnected|group_join|group_leave|group_update|loading_screen|media_uploaded|message|message_ack|message_create|message_reaction|message_revoke_everyone|qr|ready|contact_changed
- DISABLED_CALLBACKS=message_ack # PREVENT SENDING CERTAIN TYPES OF CALLBACKS BACK TO THE WEBHOOK
- ENABLE_SWAGGER_ENDPOINT=TRUE #When enabled, adding "/api-docs" to the url will open Swagger. Not recomended to production.
volumes:
- ./sessions:/usr/src/app/sessions # Mount the local ./sessions/ folder to the container's /usr/src/app/sessions folder
docker-compose pull && docker-compose up
Visit http://localhost:3000/session/start/ABCD (Replace ABCD with your desired session name)
Scan the QR on your console using WhatsApp mobile app -> Linked Device -> Link a Device (it may take time to setup the session)
Visit http://localhost:3000/client/getContacts/ABCD (Replace ABCD with your desired session name) This will list all the contacts and groups chats in json format:
{
"success": true,
"contacts": [
{
"id": {
"server": "g.us",
"user": "xxxxxxxxxxxxxxxxxx",
"_serialized": "[email protected]"
},
"number": null,
"isBusiness": false,
"isEnterprise": false,
"name": "AI XXXXX",
"type": "in",
"isMe": false,
"isUser": false,
"isGroup": true,
"isWAContact": false,
"isMyContact": false,
"isBlocked": false
}
]
}
To add wapi reposiroty to HACS, Open you Homeassistant application and navigate to HACS.
Click on Integrations.
On the upper right corner, click the three dots and select Custom repositories.
Under repository, paste the following address: https://github.com/t0mer/wapi-custom-notifier
Under category, select Integration and click ADD.
You can now see that the *wapi" was added to the custom repositories list.
can now add wapi custom component from HACS.
First, afetr the custom component installation, make sure you restarted home assistant.
To work with wapi, add the following code to your configuration.yaml file:
notify:
- platform: wapi
name: wapi whatsapp notifire
session: ABCD #Set your own session
url: http://192.168.0.238:3000/client/sendMessage #Set the url configured in the whatsapp-api docker
token: #Optional - This token shoukd be equel to the token you set in the whatsapp-api configuration.
Save the file and restart Home-assistant.
In Home assistant, under Developer tools go to services and find wapi notification service.
Insert the following lines:
service: notify.wapi_whatsapp_notifire
data:
message: The garage door has been open for 10 minutes.
title: Your Garage Door Friend
target: [email protected] #Can be contact or group chat id
And click Call Service
To send media (images and video), you can also send a media_url
in the data payload. Note that the media must be accessible by the whastapp-api container.
Multiple media files are now supported. Use the multiline feature as shown below in order to use it.
service: notify.wapi_whatsapp_notifire
data:
message: The garage door has been open for 10 minutes.
title: Your Garage Door Friend
target: [email protected] #Can be contact or group chat id
data:
media_url: |
https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Example
https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Example