├── .github └── workflows │ ├── hacs.yml │ └── hassfest .yml ├── LICENSE ├── README.md ├── custom_components └── manish │ ├── __init__.py │ ├── manifest.json │ ├── notify.py │ └── services.yaml ├── hacs.json └── screenshots ├── manish-add-button.png ├── manish-new-repo.png ├── manish-notification-service.png └── manish-notifier-add-hacs-repo.png /.github/workflows/hacs.yml: -------------------------------------------------------------------------------- 1 | name: HACS Validation 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | pull_request: 7 | schedule: 8 | - cron: "0 0 * * *" 9 | 10 | 11 | jobs: 12 | validate: 13 | runs-on: "ubuntu-latest" 14 | steps: 15 | - uses: "actions/checkout@v2" 16 | - name: HACS validation 17 | uses: "hacs/action@main" 18 | with: 19 | category: "integration" 20 | -------------------------------------------------------------------------------- /.github/workflows/hassfest .yml: -------------------------------------------------------------------------------- 1 | name: Validate with hassfest 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | pull_request: 7 | schedule: 8 | - cron: "0 0 * * *" 9 | 10 | jobs: 11 | validate: 12 | runs-on: "ubuntu-latest" 13 | steps: 14 | - uses: "actions/checkout@v2" 15 | - uses: home-assistant/actions/hassfest@master 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Tomer Klein 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![hacs_badge](https://img.shields.io/badge/HACS-Default-41BDF5.svg)](https://github.com/hacs/integration) 2 | 3 | # manish-custom-notifier- 4 | manish custom notifier for HomeAssistant allows you to send whatsapp notification using Whatsapp Cloud API easily and with minimal configuration. 5 | 6 | ## Limitations 7 | * 1000 free messages per month (Free tier) 8 | * It is only possible to send messages other than templates after the target phone responds to an initial message (Unless you use Template messages) 9 | * You can't send message to a group 10 | 11 | ## Getting started 12 | First you’ll need to follow the [instructions on this page](https://developers.facebook.com/docs/whatsapp/cloud-api/get-started) to: 13 | 14 | * Register as a Meta Developer 15 | * Enable two-factor authentication for your account 16 | * Create a Meta App – you need to create a Business App for WhatsApp 17 | 18 | Once you’ve done that, go to your app and set up the WhatsApp product. 19 | 20 | [![New app](https://techblog.co.il/wp-content/uploads/2022/12/new-app.png "New App")](https://techblog.co.il/wp-content/uploads/2022/12/new-app.png "New App") 21 | 22 | You’ll be given a temporary access token and a Phone Number ID, note these down as you’ll need them later. Set up your own phone number as a recipient and you can have a go at sending yourself a test message: 23 | 24 | [![Getting started](https://techblog.co.il/wp-content/uploads/2022/12/test-number.png "Getting started")](https://techblog.co.il/wp-content/uploads/2022/12/test-number.png "Getting started") 25 | 26 | ### Set Up Message Template 27 | 28 | In the test message above, you used the **hello_world** template. You’ll need to set up your own template for your own purposes. If you go to [“Message Templates”](https://business.facebook.com/wa/manage/message-templates/) in the WhatsApp manager you can build your own templates. 29 | 30 | In the following example, i created a template for my smat home. The template header if fixed and so is the footer. in the body i added variable for dynamic text: 31 | 32 | [![Smart Home Template](https://techblog.co.il/wp-content/uploads/2022/12/my-template.png "Smart Home Template")](https://techblog.co.il/wp-content/uploads/2022/12/my-template.png "Smart Home Template") 33 | 34 | 35 | Once you're done with the above ,you're ready to start send notifications using **manish**. 36 | 37 | 38 | ### Installation 39 | manish is now part ot the Default HACS repositories list. 40 | Just add it from the Integrations list. 41 | 42 | ### Configuration 43 | To use the custom notification, we need to add some linse to the configuration.yaml file. 44 | 45 | ```yaml 46 | notify: 47 | - platform: manish 48 | name: MaNish whatsapp notifire 49 | target: # WhatsApp number for notificatin (Without the + sign of the country_code) 50 | token: #T he token for the Whatsapp cloud API 51 | phone_number_id: #Phone number id from the Whatsapp cloud API 52 | template: # Template's name's to use 53 | language: # Template's language 54 | ``` 55 | 56 | Restart HomeAssistant and you should see a new service : 57 | [![manish custom component](https://github.com/t0mer/manish-custom-notifier/blob/main/screenshots/manish-notification-service.png?raw=true "manish custom component")](https://github.com/t0mer/manish-custom-notifier/blob/main/screenshots/manish-notification-service.png?raw=true "manish custom component") -------------------------------------------------------------------------------- /custom_components/manish/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /custom_components/manish/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain": "manish", 3 | "name": "Whatsapp notifier basde on manish api wrapper for whatsapp cloud api", 4 | "codeowners": [ 5 | "@t0mer" 6 | ], 7 | "documentation": "https://github.com/t0mer/manish-custom-notifier", 8 | "iot_class": "local_polling", 9 | "issue_tracker": "https://github.com/t0mer/manish-custom-notifier/issues", 10 | "requirements": ["ma-nish>=0.5.0"], 11 | "version": "0.2.0" 12 | } 13 | -------------------------------------------------------------------------------- /custom_components/manish/notify.py: -------------------------------------------------------------------------------- 1 | import logging 2 | from manish import MaNish 3 | from manish.template import * 4 | import voluptuous as vol 5 | 6 | import homeassistant.helpers.config_validation as cv 7 | from homeassistant.components.notify import ( 8 | ATTR_TARGET, ATTR_TITLE, PLATFORM_SCHEMA, BaseNotificationService) 9 | 10 | ATTR_PHONE_ID = "phone_number_id" 11 | ATTR_TOKEN = "token" 12 | ATTR_TEMPLATE = "template" 13 | ATTR_LANGUAGE= "language" 14 | 15 | _LOGGER = logging.getLogger(__name__) 16 | 17 | PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ 18 | vol.Required(ATTR_TARGET): cv.string, 19 | vol.Required(ATTR_PHONE_ID): cv.string, 20 | vol.Required(ATTR_TOKEN): cv.string, 21 | vol.Required(ATTR_TEMPLATE): cv.string, 22 | vol.Required(ATTR_LANGUAGE): cv.string, 23 | vol.Optional(ATTR_TITLE): cv.string, 24 | }) 25 | 26 | def get_service(hass, config, discovery_info=None): 27 | """Get the custom notifier service.""" 28 | target = config.get(ATTR_TARGET) 29 | title = config.get(ATTR_TITLE) 30 | token = config.get(ATTR_TOKEN) 31 | phone_number_id = config.get(ATTR_PHONE_ID) 32 | template = config.get(ATTR_TEMPLATE) 33 | language = config.get(ATTR_LANGUAGE) 34 | 35 | 36 | return ManishNotificationService(target, title, token, phone_number_id, template, language) 37 | 38 | class ManishNotificationService(BaseNotificationService): 39 | 40 | def __init__(self, target, title, token, phone_number_id, template, language): 41 | """Initialize the service.""" 42 | self._targets = target.split(',') 43 | self._title = title 44 | self._token = token 45 | self._phone_number_id = phone_number_id 46 | self._template = template 47 | self._language = language 48 | self._manish = MaNish(self._token,self._phone_number_id) 49 | 50 | def send_message(self, message="", **kwargs): 51 | """Send a message to the target.""" 52 | try: 53 | for target in self._targets: 54 | _LOGGER.info("Sending message to %s: %s", target, message) 55 | body = Component(type="body",parameters=[Parameter(type="text",text = message)]) 56 | result = self._manish.send_template(components=TemplateEncoder().encode([body]),recipient_id=target,template=self._template,lang=self._language) 57 | _LOGGER.warning("Whatsapp: " + str(result)) 58 | except Exception as e: 59 | _LOGGER.error("Sending message to %s: %s has failed with the following error %s", self._target, message, str(e)) -------------------------------------------------------------------------------- /custom_components/manish/services.yaml: -------------------------------------------------------------------------------- 1 | notify: 2 | description: "Send a notification using ma-nish wrapper for Whatsapp cloud API" 3 | fields: 4 | message: 5 | description: The message to send 6 | example: "Hello World" 7 | -------------------------------------------------------------------------------- /hacs.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MaNish whatsapp custom notification / notify", 3 | "render_readme": true, 4 | "country": "IL" 5 | } 6 | -------------------------------------------------------------------------------- /screenshots/manish-add-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mer/manish-custom-notifier/d6adeea76c0f649f20a7cd5b77e8dc8c9f0c7d72/screenshots/manish-add-button.png -------------------------------------------------------------------------------- /screenshots/manish-new-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mer/manish-custom-notifier/d6adeea76c0f649f20a7cd5b77e8dc8c9f0c7d72/screenshots/manish-new-repo.png -------------------------------------------------------------------------------- /screenshots/manish-notification-service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mer/manish-custom-notifier/d6adeea76c0f649f20a7cd5b77e8dc8c9f0c7d72/screenshots/manish-notification-service.png -------------------------------------------------------------------------------- /screenshots/manish-notifier-add-hacs-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mer/manish-custom-notifier/d6adeea76c0f649f20a7cd5b77e8dc8c9f0c7d72/screenshots/manish-notifier-add-hacs-repo.png --------------------------------------------------------------------------------