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
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.
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.
- With GUI. Configuration > Integration > Add Integration > LINE Bot
- If the integration didn't show up in the list please REFRESH the page
- If the integration is still not in the list, you need to clear the browser cache.
- 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
There are several formats you can use to send message.
- The messsag is plain text
service: notify.line_bot
data:
message: "Hello, world"
- The message is a simple dictionary
service: notify.line_bot
data:
message: >-
{"type": "text", "text": "Hello, world"}
- The message is a full dictionary
service: notify.line_bot
data:
message: >-
{"messages":[{"type": "text", "text": "Hello, world"}]
- 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
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
The good document to use 'LINE Bot' which is from Jason Lee.
The project is licensed under MIT License.
See LICENSE for detailed infomation.