Giter Site home page Giter Site logo

green-api-custom-notifier's Introduction

green-api-custom-notifier

green-api is a service that allows us to send and receive text, photo and video using stable WhatsApp API gateway. The service includes free account that can be used to send notifications to 3 chats (Group or Private) and many more.

green-api-custom-notifier is a Homeassistant custom notification component that enables us to send notification to Whatsapp groups using green-api.

Limitations

  • The free account is limited to 3 chats (Group or Private).

Getting started

Setup Green API account

Nevigate to https://green-api.com/en and register for a new account: Register

Fill up your details and click on Register: Create Account

Next, click on the "Create an instance": Create Instance

Select the "Developer" instance (Free): Developer Instance

Copy the InstanceId and Token, we need it for the integration settings: Instance Details

Next, Lets connect our whatsapp with green-api. On the left side, Under API --> Account, click on QR and copy the QR URL to the browser and click on "Scan QR code"

Send QR

Scan QR

Next, Scan the QR code to link you whatsapp with Green API:

QR Code

After the account link, you will notice that the instance is active by the green light in the instance header: Active Instance

Getting the Contacts and Groups

Before we can start messaging, we need to get the Contact/Group details. we can do it using Green API endpoint. On the lef side, Under API --> Service methods, click on "getContacts" and then click "Send": Get Contacts

As a result, you will get the list of Contacts and Groups.

  • The contact number ends with @c.us
  • The group number ends with @g.us

Contacts Lists

Write down the Id, you will need it to configure the notification.

Setting up the notification in Home Assistant

Download the green-api-custom-notifier, place it under the custom_components folder. Restart Home Assistant and add the following section to your configuration.yaml file:

notify:
  - platform: greenapi
    name: greenapi
    instance_id:  #REQUIRED: Set the instanceid
    token:  #REQUIRED: Set the greenapi token.
    target:  #OPTIONAL! Set the detault target. If you set the default target here, you won't have to specify it again in your service calls.
  • instance_id is the Green API instance id.
  • token is the Green API instance token.
  • target is the chat/contact/group id to send the message to:
    • For groups, the id should end with @g.us
    • For chats, the id should end with @c.us

Sending a message

To Send a message you call the service and provide the following parameters:

  • message (Required): Test to send.
  • title (OPTIONAL): Add a title for the message in bold.
  • target (OPTIONAL if you've already defined the default target in your notify service, otherwise required): The chat/group id to send the message to.

Send text message

Or from Yaml mode:

service: notify.greenapi
data:
  message: New Whatsapp component
  target: 972*********@c.us

Optional - Attach media to message

To send message with media, add the following to the data parameter:

  • file : [Path to the file]

Send media

Or from Yaml mode:

service: notify.greenapi
data:
  message: New Whatsapp component
  target: 972*********@c.us
  data:
    file: /config/images/Capture.png

Important

If the path to the file does not exist, the message will still be sent; but will log a warning.

green-api-custom-notifier's People

Contributors

ribbal avatar shlomki avatar t0mer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

green-api-custom-notifier's Issues

Unable to send message if data: field populated with action: (Error: Sending message to [email protected]: has failed with the following error 'file')

I am using this notification in a notification group which also includes iOS notifications. iOS notifications allow actions to be sent with the notification.

So my calling function includes the following in data field.

actions:

  • action: ios_Light_Off
    title: Turn Lights Off
    icon: sfsymbols:lightbulb.slash

Since the payload contains a data: field with actions, this integration looks for file: field inside data. When it doesn't find it, it doesn't send the notification.

Suggestion: If a file Key is not found in the data field, send the notification with the title and message. Ignore the rest of the elements in the data field.

Problem attachment with node-red

Hi,

if i test with developper tool and this configuration don't work:

CleanShot 2024-08-17 at 18 09 12@2x

the template:

CleanShot 2024-08-17 at 18 09 59@2x

in the log of home assistant: (the url of the file exist, because if i test to open with my ha url is work)
CleanShot 2024-08-17 at 18 11 32@2x

I test with node-red to do the same with node to convert /local/ -> /config/www but the same resultat no attachement but the log HA is not the same:

CleanShot 2024-08-17 at 18 13 26@2x

the configuration of node-red:

node-change for /local/ -> /config/www/:

{"entity_id":"sensor.plex_recently_added_movies","old_state":{"entity_id":"sensor.plex_recently_added_movies","state":"Online","attributes":{"data":[{"title_default":"$title","line1_default":"$episode","line2_default":"$release","line3_default":"$number - $rating - $runtime","line4_default":"$genres","icon":"mdi:eye-off"},{"airdate":"2024-08-17T15:17:33Z","aired":"2024-04-04","release":"$day, $date $time","flag":true,"title":"Bre","episode":"","runtime":93,"studio":"Thunder Road","genres":"Action, Thriller","rating":"โ˜… 1.8","poster":"/local/upcoming-media-card-images/plex/Plex_Recently_Added_Movies/p709.jpg","fanart":"/local/upcoming-media-card-images/plex/Plex_Recently_Added_Movies/f709.jpg"}],"friendly_name":"Plex Recently Added Movies"},"last_changed":"2024-08-17T16:07:36.179286+00:00","last_reported":"2024-08-17T17:12:59.587151+00:00","last_updated":"2024-08-17T17:12:59.587151+00:00","context":{"id":"01J5GN7YY3MAPSMX26M74Y4ECY","parent_id":null,"user_id":"c030b87449e9436baa31de5b375aa3fd"}},"new_state":{"entity_id":"sensor.plex_recently_added_movies","state":"Online","attributes":{"data":[{"title_default":"$title","line1_default":"$episode","line2_default":"$release","line3_default":"$number - $rating - $runtime","line4_default":"$genres","icon":"mdi:eye-off"},{"airdate":"2024-08-17T15:17:33Z","aired":"2024-04-04","release":"$day, $date $time","flag":true,"title":"Breathe","episode":"","runtime":93,"studio":"Thunder Road","genres":"Action, Thriller","rating":"โ˜… 1.8","poster":"/config/www/upcoming-media-card-images/plex/Plex_Recently_Added_Movies/p709.jpg","fanart":"/local/upcoming-media-card-images/plex/Plex_Recently_Added_Movies/f709.jpg"}],"friendly_name":"Plex Recently Added Movies"},"last_changed":"2024-08-17T16:07:36.179286+00:00","last_reported":"2024-08-17T17:13:36.185422+00:00","last_updated":"2024-08-17T17:13:36.185422+00:00","context":{"id":"01J5GN92NSN9S7A1SMWBVXCC19","parent_id":null,"user_id":null},"timeSinceChangedMs":3960014}}

CleanShot 2024-08-17 at 18 16 25@2x

and the config node call-service:
CleanShot 2024-08-17 at 18 17 48@2x

CleanShot 2024-08-17 at 18 18 06@2x

[Feature Request] Add support for defining target in the notify service config, in order to be able to create notify groups

Some notify services such as the Telegram Bot allow defining the target (chat_id) in the notify service itself.
This has multiple benefits:

  1. You don't have to specify the target every time you want to send a message (e.g: notify.tomer).
  2. Allows creating notify groups, which simplify the usage of notification services.

Here's an example:

notify:
  - name: daddy
    platform: telegram
    chat_id: 11111111

  - name: mommy
    platform: telegram
    chat_id: 22222222

  - name: girl
    platform: telegram
    chat_id: 33333333

  - name: family
    platform: group
    services:
      - service: daddy
      - service: mommy
      - service: girl

This way, you could simply call notify.family and all notify accounts would get triggered, without having to specify targets ids.
Currently, the integration doesn't support that, and you must specify the target every time you want to use the notify.greenapi service.

After this change is implemented, this is how I expect the configuration to look like:

notify:
  - platform: greenapi
    name: Tomer
    instance_id: #Set Instance ID
    token: #Set Token
    target: #Set Target

And the service would be called this way:

- service: notify.tomer
  data:
    message: "Hello World"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.