0%

Line Notify 結束服務,轉移到 Slack、Telegram、Discord

push_yourself_bg
Line Notify替代方案比較圖表:呈現Discord、Telegram、Slack和Line Message API四種服務在設置難度、功能支持和費用方面的對比。Discord設置簡單且免費;Telegram設置中等且免費;Slack功能豐富但部分付費;Line Message API功能最完整但設置複雜且需付費。適用於Line Notify將於2025年3月31日停止服務後的替代選擇。
圖1: Line Notify替代方案比較 - 2025年3月服務終止後的選擇

前言

LINE Notify結束服務公告

Line Notify 宣布要停止服務了,
預計於 2025年3月31日結束
需要轉移的大家,剩下五個多月可以轉移

自己原本比較常使用 Slack 來做類似的推播,同時也串了 Line Notify
在 Thread 上轉貼訊息後發現很多人也推薦其他的服務像是 Telegram、Discord 等等

由 @darrell_tw_ 發佈
在 Threads 查看

Discord Webhook

Discord 是目前設置的經驗來說非常簡單的,基本上沒有什麼複雜的權限和 Key 要注意,
簡單的產生個 Bot 和取得 webhook URL 就可以開始使用了。

建立 Bot,取得 webhook網址

setup_discord_webhook_url_quickly

只要簡單一個步驟就能快速建立 Bot 和取得 webhook URL

發送通知

以 Postman 當作舉例,只要把 URL 換成上面拿到的 webhook URL
並用下面的範例 json payload 送出即可!
請注意送出後右邊的 response 顯示空白是正常的,只會顯示 Status Code 204

send_push_to_discord

iOS 端接收到的通知如下圖

discord_push_in_ios
push_content_in_discord

CURL 語法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
curl --location 'https://discord.com/api/webhooks/換成你的webhook URL' \
--header 'Content-Type: application/json' \
--data '{
"content": "測試訊息",
"embeds": [
{
"title": "Embed Title",
"description": "This is an embed description.",
"color": 2123412,
"image": {
"url": "圖片網址"
}
}
]
}'

相關的訊息 Payload 可以參考 Discord API 文件
例如上方範例使用的就是夾帶了一個 Embed 的 Object

Discord embed-object
可以嘗試增加或修改欄位來看看不同的效果

預覽調整訊息的工具

下面介紹的工具是如果你想要建立一個較複雜的訊息
想要有個地方先排版或預覽訊息的樣式
那可以先到這些工具的介面來調整
最後複製 JSON payload 回去程式端發送

https://discohook.org/

discohook_website

https://toolscord.com/webhook

toolscord_website

Telegram Bot Webhook

找 BotFather 建立 Bot

在 Telegram 中可以搜尋到 BotFather,開始聊天後他就會詢問你是否要建立 Bot

telegram_find_botfather

會有個互動式對話引導你建立

  1. 輸入 /newbot
  2. 輸入 Bot 的名稱
  3. 輸入 Bot 的 username (username 需要是唯一的,並且要是 bot 結尾)
  4. 最後會提供 API Token
telegram_create_bot

和 Bot 一起建立群組,取得 chat_id

這邊會是比較麻煩的地方
好像需要先和 Bot 一起建立一個群組或是 Channel
並且用 getUpdates 來取得 chat_id

1
https://api.telegram.org/bot{剛剛取得的API Token}/getUpdates

發送後會拿到一個 JSON 的 response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"ok": true,
"result": [
{
"update_id": xxx,
"message": {
"message_id": 4,
"from": {...},
"chat": {
"id": -1111111111, // 需要的 chat_id
"title": "DarrellTW_webhook",
"type": "group",
"all_members_are_administrators": true
},
"date": 1728343722,
"group_chat_created": true
}
}
]
}

發送訊息給 Telegram Bot

利用 Postman 發送訊息給 Telegram Bot

1
POST https://api.telegram.org/bot{剛剛取得的API Token}/sendMessage
send_api_to_telegram_in_postman

發送成功後,訊息通知就會顯示在電腦和手機上

telegram_bot_message_in_iphone
telegram_bot_message_in_mac

CURL 語法

1
2
3
4
curl --location 'https://api.telegram.org/bot{剛剛取得的API Token}/sendMessage' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'chat_id=-1111111111' \
--data-urlencode 'text=Hello, this is a test message!'

訊息 Payload 文件

Telegram Bot API - sendMessage

目前沒有找到一些可以預覽調整訊息的工具或服務,
有找到一個 GitHub 上的專案,但因為更新時間已經是八年前,就沒有深入研究了
網址 Playground

提供一個請 chatGPT 幫忙產生的 payload

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
"chat_id": "-4545338933",
"text": "\uD83D\uDC4B *歡迎!* \n\n\uD83C\uDFC3\u200D\u2642\uFE0F *快速操作:*",
"parse_mode": "MarkdownV2",
"disable_web_page_preview": true,
"reply_markup": {
"inline_keyboard": [
[
{
"text": "\uD83D\uDC68\u200D\uD83C\uDFEB 聯繫我們",
"url": "https://t.me/username"
},
{
"text": "\u2B50 給我們評價",
"callback_data": "rate_us"
}
],
[
{
"text": "\uD83D\uDD17 瀏覽我們的網站",
"url": "https://example.com"
}
]
]
}
}

訊息的樣式會是:

advanced_telegram_message_payload

Slack

建立 Slack App

Slack 也是一樣需要先建立個 App,
workspace 這邊可以進入到管理頁面

manage_slack_app_in_workspace

接著就能建立一個 App 了

create_app_in_slack

要開啟 Incoming Webhook 的功能

enable_webhook_in_slack_app

選擇要傳送的 channel

select_channel_for_webhook_push

最後就能拿到這個 Webhook URL

slack_get_webhook_url

發送訊息給 Slack Bot

介面上面很貼心就已經附上了 CURL 語法測試

send_slack_via_postman

成功就會看到訊息跟通知,並且回傳一個 Status Code 200 加上 ok 非常簡潔有力的回應

slack_notification_in_ios

CURL 語法

1
curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/{換成你的webhook URL}'

Slack Block Kit Builder

Block Kit Builder
可以用來排版訊息格式的工具,並且也內建了多個模組可以選擇!

slack_block_kit_builder

測試時按下右上角的 Send to Slack 按鈕,
就能即時看到送出的訊息會長什麼樣子

列出幾個模組提供參考

slack_block_kit_builder_templates

這邊是我用來推播給自己氣象資訊用的格式

darrelltw_slack_message_usage

Line Messagge API

如果你的需求或環境不適合轉移到其他服務平台上
且願意付費,那 Line Messagge API 就是唯一的最佳解

計費

line_message_api_pricing

免費方案是 200 次發送/$0/月
中用量 3000 次發送/$800/月
高用量 6000 次發送/$1200/月

使用方式

由於這需要技術上的串接,
我的另外一篇有提到如何用 n8n 這個自動化工具來串接 Line Messgae API

n8n 串接 Line Messgae API

Line Notify 的替代方案之一 Line Message API,介紹怎麼用 n8n 的 Request 來發送和接收 webhook,也會提供模板範例

n8n 串接 Line Messgae API

用量注意事項

另外有一點必須要特別注意!!!

如果在群組發送 Line Message API
會根據群組的人數來消耗次數
當你用 Bot 發送 Message API 到該群組時
例如群組內有 10 個使用者,會消耗 10 次

所以大量發送訊息到群組會非常快消耗次數,要注意這件事情

檢查目前剩餘餘額Quota

Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# python 版本

def check_quota():
"""查詢LINE Message API剩餘配額"""
with get_api_client() as api_client:
api_instance = MessagingApi(api_client)
try:
# 獲取配額上限
message_quota = api_instance.get_message_quota()

# 獲取已使用配額
consumption = api_instance.get_message_quota_consumption()

# 計算剩餘配額
total = message_quota.value
used = consumption.total_usage
remaining = total - used

print("===== LINE配額資訊 =====")
print(f"配額類型: {message_quota.type}")
print(f"總配額: {total:,}")
print(f"已使用: {used:,}")
print(f"剩餘: {remaining:,} ({round((remaining/total)*100, 2)}%)")
print("=======================")

return {
"type": message_quota.type,
"total": total,
"used": used,
"remaining": remaining
}
except ApiException as e:
print(f"✗ 查詢配額失敗: {e}")
return {"error": str(e)}