A simple message bot for Lark (Feishu / 飞书).
This is a small server application, you may need to configure nginx to serve over https and control access.
app-id - lark app id (you can also use env LARK_APP_ID)
app-secret - lark app secret (you can also use env LARK_APP_SECRET)
listen - private http server address
verbosity - debug, info, notice, warning, error, critical
masters - user ids to work for, separated by ","
Steps to create Feishu bot:
- Create Custom App
- Go to Features, enable "Using Bot"
- Go to Event Subscriptions page, set Request URL to this server address. And add "Accept to messages" event.
- Create a new version, set availability status to all, publish it and wait for review.
- You may need to add more permissions for the
members
command.
Available commands that you can send to the bot:
Create new chat with name and add you to the new chat.
Add you to one or more chats.
Destroy one or more chats.
List names and user ids of the chat with chat_id.
Extra permissions for this command:
- Access user basic information from the contact
- Access contacts by application identity
Add one or more users to chat.
Remove one or more users from chat.
List all chats created by the bot.
Show the author of the bot.
Show your user id.
Make an HTTP JSON-RPC request to send message to the chat (so that everyone in the chat receives this message).
curl http://127.0.0.1:32123/jsonrpc/ --data \
'{"method":"Lark.SendMessage","params":[{"chat_id":"oc_xxxx","content":"test"}]}'
Send plain text to chat.
{
"chat_id": "oc_xxxx",
"content": "text"
}
Send message with text, links, images to chat. See docs.
{
"chat_id": "oc_xxxx",
"post": {
"zh_cn": {
"title": "Title",
"content": [
[
{
"tag": "text",
"text": "Test: "
},
{
"tag": "a",
"text": "Google",
"href": "https://www.google.com"
}
],
[
{
"tag": "text",
"text": "some text"
}
]
]
}
}
}
nginx config example:
server {
listen 443 ssl http2;
server_name lark.yourdomain.com;
location /204/ {
proxy_pass http://127.0.0.1:32123;
}
location /events/ {
proxy_pass http://127.0.0.1:32123;
}
location /jsonrpc/ {
satisfy any;
allow 8.9.10.11; # ip addresses of your other servers
allow 12.13.14.15; # ip addresses of your other servers
deny all;
auth_basic "closed site";
auth_basic_user_file /etc/nginx/lark.passwd;
proxy_pass http://127.0.0.1:32123;
}
location / {
return 404;
}
}