Skip to content

jekalmin/line_bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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. Install via custom component of HACS.

    Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

  2. Go to https://developers.line.biz/console

  3. Retrieve "Channel access token" and "Channel secret" from Line Console

  4. Install integration

    • [Settings] > [Devices and Services] > [Add Integration] > [Line Bot]
    • Use "Channel access token" and "Channel secret" retrieved from above (#3). 스크린샷 2024-12-22 오후 9 00 33
  5. 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
    스크린샷 2024-12-22 오후 9 13 12
  6. Click "Verify" button to verify URL is valid. It has to return "Success"

    11

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

  8. Send any message to a bot

  9. Go to [Configure > Add a chat] and follow the directions.

    configure add a chat configure a chat
  10. Try examples

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

Packages

No packages published

Languages