Giter Club home page Giter Club logo

line-bot's Introduction

line-bot hacs_badge

LINE bot plugin for Home Assistant

This project is modified from yun-s-oh/Homeassistant

โš  Note

This component is for LINE bot

If you plan to integrate LINE Notify, use yun-s-oh's component instead

Usage

Install

You can install component with HACS custom repo: HACS > Integrations > 3 dots (upper top corner) > Custom repositories > URL: osk2/line-bot > Category: Integration

Or manually copy line-bot folder to custom_components folder in your config folder.

Configuration

Add following entry as default one in your configuration.yaml

notify:
  - name: line_bot
    platform: line_bot
    client_id: 'CLIENT_ID'
    access_token: 'CHANNEL_ACCESS_TOKEN'

Then restart HA.

After enable servide notify.line-bot, you can use integration to add another client_id and access_token without restart HA.

  1. With GUI. Configuration > Integration > Add Integration > LINE Bot
    1. If the integration didn't show up in the list please REFRESH the page
    2. If the integration is still not in the list, you need to clear the browser cache.
  2. Enter name (use different name to default one), client_id and access_token.

See Additional Information for detail of retrieving client_id and access_token

Call Service

There are several formats you can use to send message.

  1. The messsag is plain text
service: notify.line_bot
data:
  message: "Hello, world"
  1. The message is a simple dictionary
service: notify.line_bot
data:
  message: >-
    {"type": "text", "text": "Hello, world"}
  1. The message is a full dictionary
service: notify.line_bot
data:
  message: >-
    {"messages":[{"type": "text", "text": "Hello, world"}]
  1. Specify the LINE bot name
service: notify.line_bot
data:
  message: >-
    {"messages":[{"type": "text", "text": "Hello, world"}]
  data:
    name: line_bot_family

See Additional Information for detail of LINE Message Object

Additional Information

client_id

client_id is LINE user ID or group ID

Retrieve client_id can be tricky, here's how I get client_id

  1. Create Firebase Cloud Functions
  2. Deploy following script to Cloud Functions
const functions = require('firebase-functions');

exports.helloWorld = functions.https.onRequest((request, response) => {
  const events = request.body.events
  const source = events.length > 0 ? events[0].source : null;

  if (source) {
    functions.logger.info(source.groupId || source.userId);
  }
  response.send("Hello from Firebase!");
});
  1. Enable webhook for LINE Messaging API image
  2. Friend bot account or invite bot to your group chat
  3. You should be able to see client_id in Cloud Functions log after sending some nice message to your bot image
  4. Disable webhook again or your log will be flooded

access_token

access_token is channel access token which can be generate from LINE Developer website

Visit https://developers.line.biz/console/channel/<YOUR CHANNEL ID>/messaging-api

The token is listed under Channel access token or your can create one there image

LINE Message Object

This component supports all kinds of message types that are listed in Messaging API reference

Text message example

{
  "messages": [{
    "type": "text",
    "text": "Hello, world"}]
}

Flex message example

{
  "type": "flex",
  "altText": "this is a flex message",
  "contents": {
    "type": "bubble",
    "body": {
      "type": "box",
      "layout": "vertical",
      "contents": [
        {
          "type": "text",
          "text": "hello"
        },
        {
          "type": "text",
          "text": "world"
        }
      ]
    }
  }
}

See Also

Flex Message Simulator to help you build flex message object

One More Information

The good document to use 'LINE Bot' which is from Jason Lee.

License

The project is licensed under MIT License.

See LICENSE for detailed infomation.

line-bot's People

Contributors

osk2 avatar

Stargazers

 avatar  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.