Skip to content

jekalmin/line_bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HASS-Line-Bot

Home Assistant custom component for notifying message via Line Messaging API (https://developers.line.biz/en/docs/messaging-api/overview/)

Usage

service: line_bot.send_message
data:
  to: me
  message:
    type: text
    text: "Hello World!"

Prequisite

  • Created a channel from Line Console.
    • Follow instructions from the link to create a new channel.

Installation

  1. Copy

    /custom_components/line_bot/
    

    into

    <config directory>/custom_components/line_bot/
    
  2. Go to https://developers.line.biz/console

  3. Select "Provider", and then "Channel" created from prequisite.

  4. Set configuration.yaml as below (retrieve "Channel access token" and "Channel secret" from Line Console)

    line_bot:
      token: !secret line_bot_token
      secret: !secret line_bot_secret
  5. Restart HomeAssistant

  6. Set "Webhook URL" from "Messaging API" tab of Line Console as below

    • Webhook URL is base_url + "/api/line/callback"
    • Your HomeAssistant URL has to support https

    10

  7. Click "Verify" button to verify URL is valid. It has to return "Success"

    11

  8. Add a bot as a friend by either QR code or Bot ID

  9. Send any message to a bot

  10. Get chat_id from HomeAssistant notification

    12

  11. Set "chat_id" into "allowed_chat_ids" of configuration.yaml

  12. Restart HomeAssistant and try examples

Configuration

Example configuration.yaml:

line_bot:
  token: !secret line_bot_token
  secret: !secret line_bot_secret
  allowed_chat_ids:
    me: !secret line_chat_id

Configuration variables:

key required default dataType description
token yes string channel access token (to issue a channel access token, click Issue on the "Channel settings" page on the console.)
secret no string channel secret. Only required to use webhook.
allowed_chat_ids yes dictionary any name as a key, ID of target recipient as a value. Do not use the LINE ID found on LINE (see API Documentation)

Services

line_bot.send_message

service data attribute required dataType description
to no string name of chat ID from allowed_chat_ids in configuration.yaml file to push message.
reply_token no string reply_token received from webhook event to reply message.
message yes Message eg. Text message, Image message,Template message, etc...

example

a1

service: line_bot.send_message
data:
  to: me
  message:
    type: text
    text: "Hello World!"

line_bot.send_button_message

service data attribute required dataType description
to no string name of chat ID from allowed_chat_ids in configuration.yaml file to push message.
reply_token no string reply_token received from webhook event to reply message.
buttons yes list a list of Actions (max: 4)

example

162292

service: line_bot.send_button_message
data:
  to: me
  text: What do you want to do?
  buttons:
    # MessageAction (https://developers.line.biz/en/reference/messaging-api/#message-action)
    - label: Turn off the light
      text: light off
    # PostbackAction (https://developers.line.biz/en/reference/messaging-api/#postback-action)
    - label: Buy
      data: action=buy&itemid=111
    # UriAction (https://developers.line.biz/en/reference/messaging-api/#uri-action)
    - uri: https://www.google.com/
      label: Google

line_bot.send_confirm_message

service data attribute required dataType description
to no string name of chat ID from allowed_chat_ids in configuration.yaml file to push message.
reply_token no string reply_token received from webhook event to reply message.
buttons yes list a list of Actions (max: 2)

example

162289

service: line_bot.send_confirm_message
data:
  to: me
  text: Are you sure?
  buttons:
    # PostbackAction 
    - text: Yes 
      data: action=buy&itemid=111 # equivalent to {"label" : "Yes", "data" : "action=buy&itemid=111 "}
    # MessageAction
    - text: No # equivalent to {"text" : "No", "label" : "No"}

Events

line_webhook_text_received

event data attribute dataType description
reply_token string It is used to reply message.
event MessageEvent Event object which contains the sent message. The message field contains a message object which corresponds with the message type. You can reply to message events.
content TextMessage Message object which contains the text sent from the source.
text string actual text received

line_webhook_postback_received

event data attribute dataType description
reply_token string It is used to reply message.
event PostbackEvent Event object for when a user performs an action on a template message which initiates a postback. You can reply to postback events.
content Postback Postback
data string Postback data
data_json dictionary Postback data as JSON object
params dictionary JSON object with the date and time selected by a user through a datetime picker action. Only returned for postback actions via the datetime picker.

About

Home Assistant custom component for sending message via Line Messaging API (https://developers.line.biz/en/docs/messaging-api/overview/)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages