LINE bot plugin for Home Assistant
This project is modified from yun-s-oh/Homeassistant
This component is for LINE bot
If you plan to integrate LINE Notify, use yun-s-oh's component instead
Install line-bot
via HACS is recommended
HACS > Integrations > 3 dots menu (top right) > Custom repositories > URL: osk2/line-bot
> Category: Integration
Copy custom_components/line_bot
to custom_components
Add following entry in configuration.yaml
notify:
- name: line_bot
platform: line_bot
client_id: 'CLIENT_ID'
access_token: 'CHANNEL_ACCESS_TOKEN'
See Additional Information for detail of retrieving client_id
and access_token
A profile means a set of client_id
and access_token
.
You can add more notify service by repeating above steps. You can also create profile via UI to simplify the process
- Configuration > Integration > Add Integration > LINE Bot
- Enter profile name (different to entry name in configuration.yaml), client_id and access_token.
See Change Profile to learn how to use profile
Passing LINE message object into service
service: notify.line_bot
data:
message: >-
{"messages":[{"type": "text", "text": "Hello, world"}]}
Just in case you are too lazy to pass full object, plain text is also supported
service: notify.line_bot
data:
message: 'Hello, world'
service: notify.line_bot
data:
message: >-
{"messages":[{"type": "text", "text": "Hello, world"}]}
data:
profile: cool_line_bot # Profile name
See Additional Information for detail of LINE Message Object
client_id
is LINE user ID or group ID
Retrieve client_id
can be tricky, here's how I get client_id
- Create Firebase Cloud Functions
- 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!')
})
- Enable webhook for LINE Messaging API
- Friend bot account or invite bot to your group chat
- You should be able to see
client_id
in Cloud Functions log after sending some nice message to your bot - Disable webhook again or your log will be flooded
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
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"
}
]
}
}
}
- Flex Message Simulator to help you build flex message object
- #教學 打造你的智慧家庭吧! 把 LINE 提醒變得更有型 (Thanks Jason Lee 👏)
The project is licensed under MIT License.
See LICENSE for detailed infomation.