Giter VIP home page Giter VIP logo

line_bot's Introduction

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.

line_bot's People

Contributors

jekalmin avatar

Stargazers

Lee Kyung Joon avatar kunari avatar Son, Sang Jin avatar

Watchers

 avatar  avatar kunari avatar

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.