Line Notify to Telegram Bot Migration|Fast 10-Minute Guide for Enhanced Notifications
Discover how users can seamlessly transfer their Line Notify personal alerts to Telegram Bot, a free and more powerful notification service, with this step-by-step 10-minute guide for improved messaging efficiency.
点击这里查看本文章简体中文版本。
點擊這裡查看本文章正體中文版本。
This post was translated with AI assistance — let me know if anything sounds off!
10-Minute Quick Transfer from Line Notify to Telegram Bot Notifications
Step-by-Step Guide to Migrate Line Notify Personal Notification Service to the Also Free and More Powerful Telegram Bot
Photo by Lana Codes
LINE Notify Service Termination Announcement
Thank you for using LINE Notify for a long time.
Since its launch in September 2016, LINE Notify has been dedicated to serving developers. To provide better services and focus resources on similar future products, we have decided to end this service on March 31, 2025. We sincerely thank all users who have supported and used LINE as a notification integration service over the years.
If you still need to use LINE to send notifications to users, it is recommended to switch to the more feature-rich Messaging API.
Excerpted from Line Notify Official Website, Line announced on 2024/10/08 that Line Notify will be completely shut down on 2025/04/01. To continue using Line for message notifications, only the paid Message API can be used.
The advantage of Line Notify is that it is very easy to integrate, making it convenient and useful for personal notification bots. Some Line Bots or third-party services also use Line Notify for notifications (e.g., Louisa, your order notification feature). However, it has several drawbacks, such as limited message content, no group segmentation (all messages are sent to the Line Notify Bot), and message length restrictions, among others.
With Line Notify announcing its termination, it also gave me an opportunity to migrate to other communication and notification services:
Slack: The free version only keeps messages for 30 days. My notifications are more personal, so using Slack feels a bit like overkill. (For sending messages with Slack, refer to my previous article: Slack & ChatGPT Integration)
Discord: My notifications are more personal, which feels a bit like overkill.
Telegram: Free, almost unlimited use.
For me, Telegram’s messaging service better meets my original Line Notify usage needs. I need a channel that can receive notifications, preferably with different channels for different needs. The more diverse the acceptable content and formats, the better, and it should be easy and quick to integrate. Telegram meets all these requirements and also supports interactive features with bots.
Results
First, here is the final result image (using Github Star notification, Repo Stats notification as examples):
✅ When someone stars the Repo, it triggers a Webhook -> Google Apps Script -> Telegram Bot to send a notification to Telegram — Github Stats Group
✅ Google Apps Script Daily Schedule -> Fetch Github Repo Stats -> Telegram Bot Sends Notification to Telegram — Github Stats Group
✅ Use the
/update
Telegram Bot Command to trigger fetching Github Repo Stats status -> Telegram Bot sends notification to Telegram — Github Stats Group
Compared to the original Line Notify
❌ All messages that cannot be categorized or grouped are sent to Line Notify
❌ Cannot set special settings for individual messages (such as notification sound, mute…)
❌ Unable to input messages for interaction
Table of Contents
Setting up a Telegram Bot
Migrating Line Notify Message Sending to Telegram Bot (Google Apps Script)
Interacting with Telegram Bot (Commands) using Google Apps Script
(1/2) Setting up Telegram Bot
Applying for a Telegram Bot is very simple; you don’t even need to open a webpage. Just interact with the official BotFather bot.
Step 1. Apply for a Telegram Bot
After installing and registering for the Telegram service, click to add BotFather bot as a friend.
Open and join BotFather bot
After joining, send the message “/newbot” to create your bot.
Enter your bot name
Enter your bot username (must be unique and end with
bot
, for example, mine iszhgchgli_bot
)Your bot link, click to start using (e.g. t.me/harrytest56_bot)
Get your
BOT_API_Token
, please keep it safe ⚠️⚠️⚠️
Click the link obtained in step 4 to start using the Bot:
Currently, there are no features available. You can tap the top right corner Info to edit your name or upload a profile picture.
Step 2. Create a Telegram Notification Group & Add the Bot Account
I want different types of personal notifications to be sent to different Groups, but here only one My Notify Group is created for the Demo.
You can create different Groups based on actual needs and add or configure bots step by step.
New Group
Search for your bot account & click Join
Set Group Name and Avatar
Step 3. Obtain Group Chat ID
Telegram Bot API does not provide a direct endpoint to get the list of Groups or Group Chat IDs. You can only obtain the bot’s message list through /getUpdates
and extract the Group Chat IDs from there:
Request:
1
curl 'https://api.telegram.org/bot你的_BOT_API_Token/getUpdates'
The Telegram API format is
https://api.telegram.org/bot
your_BOT_API_Token/getUpdates
. The BOT API Token string must be prefixed with thebot
string.Example:
curl 'https://api.telegram.org/bot7814194578:AAEWpPJvKn06ID7D9FjV65aDKQLkGkz8cc8/getUpdates'
Response:
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
{
"ok": true,
"result": [
{
"update_id": 706454235,
"my_chat_member": {
"chat": {
"id": -4532420331,
"title": "My Nofify",
"type": "group",
"all_members_are_administrators": false
},
"from": {
"id": 986128250,
"is_bot": false,
"first_name": "Harry",
"last_name": "Li",
"username": "zhgchgli"
},
"date": 1728726861,
"old_chat_member": {
"user": {
"id": 7814194578,
"is_bot": true,
"first_name": "Harry Test",
"username": "harrytest56_bot"
},
"status": "left"
},
"new_chat_member": {
"user": {
"id": 7814194578,
"is_bot": true,
"first_name": "Harry Test",
"username": "harrytest56_bot"
},
"status": "member"
}
}
},
{
"update_id": 706454236,
"message": {
"message_id": 1,
"from": {
"id": 986128250,
"is_bot": false,
"first_name": "Harry",
"last_name": "Li",
"username": "zhgchgli"
},
"chat": {
"id": -4532420331,
"title": "My Nofify",
"type": "group",
"all_members_are_administrators": true
},
"date": 1728726861,
"group_chat_created": true
}
},
{
"update_id": 706454237,
"message": {
"message_id": 2,
"from": {
"id": 986128250,
"is_bot": false,
"first_name": "Harry",
"last_name": "Li",
"username": "zhgchgli"
},
"chat": {
"id": -4532420331,
"title": "My Nofify",
"type": "group",
"all_members_are_administrators": true
},
"date": 1728726864,
"new_chat_photo": [
{
"file_id": "AgACAgUAAxkBAAMCZwpHUEaLZSvFFYu8GiO-8qI_jVYAApfAMRu0B1BUJP-4u2wF6scBAAMCAANhAAM2BA",
"file_unique_id": "AQADl8AxG7QHUFQAAQ",
"file_size": 5922,
"width": 160,
"height": 160
},
{
"file_id": "AgACAgUAAxkBAAMCZwpHUEaLZSvFFYu8GiO-8qI_jVYAApfAMRu0B1BUJP-4u2wF6scBAAMCAANiAAM2BA",
"file_unique_id": "AQADl8AxG7QHUFRn",
"file_size": 15097,
"width": 320,
"height": 320
},
{
"file_id": "AgACAgUAAxkBAAMCZwpHUEaLZSvFFYu8GiO-8qI_jVYAApfAMRu0B1BUJP-4u2wF6scBAAMCAANjAAM2BA",
"file_unique_id": "AQADl8AxG7QHUFQB",
"file_size": 37988,
"width": 640,
"height": 640
}
]
}
}
]
}
You can find the corresponding nested JSON data for Group Name + type=group in the response, where the id is the Group Chat ID:
1
2
3
4
5
6
"chat": {
"id": -4532420331,
"title": "My Nofify",
"type": "group",
"all_members_are_administrators": false
}
Group Chat Id
=-4532420331
⚠️⚠️⚠️️ If your response is empty
{ "ok": true, "result": [] }
, please try sending a message in your group (e.g.Hello
) and then call the API again. It should work.
Step 4. Send Message
We can use /sendMessage
to send messages to a Group.
Request:
1
2
3
curl 'https://api.telegram.org/bot你的_BOT_API_Token/sendMessage' \
--form 'chat_id="Group Chat Id"' \
--form 'text="Message content"'
Example:
1
2
3
curl 'https://api.telegram.org/bot7814194578:AAEWpPJvKn06ID7D9FjV65aDKQLkGkz8cc8/sendMessage' \
--form 'chat_id="-4532420331"' \
--form 'text="test"'
Response & Result:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"ok": true,
"result": {
"message_id": 5,
"from": {
"id": 7814194578,
"is_bot": true,
"first_name": "Harry Test",
"username": "harrytest56_bot"
},
"chat": {
"id": -4532420331,
"title": "My Nofify",
"type": "group",
"all_members_are_administrators": true
},
"date": 1728727847,
"text": "test"
}
}
- Sent successfully and received the above response
- Replying in the Telegram Group will display the message content just sent.
(2/2) Migrate Line Notify Message Sending to Telegram Bot (Google Apps Script)
My personal notification bot service is implemented using Google Apps Script, so I will use Google Apps Script (JavaScript-like) as an example for conversion.
Original Line Notify Sending Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const lineToken = "XXXX";
function sendLineNotifyMessage(message) {
var url = 'https://notify-api.line.me/api/notify';
var options = {
method: 'post',
headers: {
'Authorization': 'Bearer '+lineToken
},
payload: {
'message': message
}
};
const response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
You can see it is very simple, convenient, and easy to use…
Code for migrating to a Telegram Bot:
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
const telegramToken = "your_BOT_API_Token";
const TelegramChatId = {
GA: -123456,
GITHUB: -123457,
MEDIUM: -123458
};
function sendNotifyMessage(message, chatId) {
var url = "https://api.telegram.org/bot"+telegramToken+"/sendMessage";
const payload = {
"chat_id": chatId,
"text": message,
"parse_mode": "Markdown"
}
const options = {
'method': 'post',
'contentType': 'application/json',
'muteHttpExceptions': true,
'payload': JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
Information obtained from the previous Telegram Bot setup steps.
telegramToken
=your_BOT_API_Token
TelegramChatId
here is a custom method I defined because, in practice, I want different notifications to be sent to different groups. Therefore, I created a structure to manage target groups and theirGroup Chat Id
.
/sendMessage
API parameters, for more parameters and details please refer to the official documentation, below are the parameters I commonly use:
text: Message content (required)
chat_id: Target Group Chat Id (required)
parse_mode: Message content parsing method, here I specify
Markdown
disable_web_page_preview: Whether to disable link previews in the message content. Setting this to
true
here will turn off previews, making the message display simpler.
Usage:
1
2
sendNotifyMessage("Hello", TelegramChatId.MEDIUM) // Send Hello message to MEDIUM Group Chat Id
sendNotifyMessage("Hello", -1234) // Send Hello message to -1234 Group Chat Id
Results
Using my Github Repo Star Notifier bot as an example:
Verification successful! When someone stars my Repo, the notification is correctly sent to the Telegram Group! 🎉🎉🎉
For the setup, you can refer to my previous article “Using Google Apps Script in Three Steps to Create a Free Github Repo Star Notifier”
Set Custom Sounds or Mute
Even better than Line Notify is that we can set different notification sounds or mute options for different groups.
Interacting with Telegram Bot (Command) x Using Google Apps Script
Besides replacing the Notify function, Telegram Bot can also easily implement user interaction features — Telegram Bot Command.
Back to my use case, my bot sends notification messages to me either on a schedule or triggered by a Webhook; but sometimes I want to manually trigger the bot to get the current result immediately. Previously, Line Notify did not have this feature. With Google Apps Script, the only option was to forcibly set up a URL that triggers the bot whenever opened, which is not user-friendly.
Telegram Bot Command lets me directly enter command messages and have the bot immediately perform the tasks I want.
This article uses Google Apps Script as an example. For a detailed introduction to Google Apps Script, please refer to my previous article “Using Google Apps Script to Achieve Google Services RPA Automation”.
Step 1. Implement Command Handling Logic Using Google Apps Script
Go to the Google Apps Script homepage
Top left “Create New Project”
Click “Untitled Project” to enter the project name, e.g.
Telegram
Paste the basic code:
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
36
37
const telegramToken = "your_BOT_API_Token";
function doPost(e) {
const content = JSON.parse(e.postData.contents);
if (content.message && content.message.text) {
const command = content.message.text.split(' ')[0];
const chatId = content.message.chat.id;
if (command.startsWith("/update")) {
// Received /update command
// Handle your tasks here... then respond...
sendNotifyMessage("Hello.....\nCommand:"+command, chatId);
}
}
return HtmlService.createHtmlOutput("OK!");
}
function sendNotifyMessage(message, chatId) {
var url = "https://api.telegram.org/bot"+telegramToken+"/sendMessage";
const payload = {
"chat_id": chatId,
"text": message,
"disable_web_page_preview": true,
"parse_mode": "Markdown"
}
const options = {
'method': 'post',
'contentType': 'application/json',
'muteHttpExceptions': true,
'payload': JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
telegramToken
=your_BOT_API_Token
In the demo program above, when receiving a POST request with the Command parameter set to
/update
, it responds with你好…
to simulate processing and replying after receiving the command.
Step 2. Complete Google Apps Script Web Deployment
Top right corner “Deploy” -> “Add Deployment Task”
Top left corner “Settings” -> “Web Applications”
Who can access if “Everyone” is selected?
Add a deployment task and select “Grant Access”
Exit the account window and select your Google login account
A warning window will pop up. Select “Advanced” -> “Go to
Project Name
(unsafe)”Select “Allow”
- Web application URL:
Your Webhook URL
.
Copy it.
e.g.https://script.google.com/macros/s/AKfycbx2oFv-eB4LezdOk3P3aoEZVhx_PI6n_YnTNP7WVVQSaiRU52di5bKNThsvIZxus3Si/exec
For deploying, updating, using, and debugging Google Apps Script web applications, please refer to my previous article “Automating Google Services with Google Apps Script RPA”.
⚠️⚠️⚠️ Please note, if the Google Apps Script code changes, you must click Deploy -> Manage Deployments -> Select Create New Version for the changes to take effect. For details, please refer to the article above.
⚠️⚠️⚠️Please note, if the Google Apps Script code is changed, you must click Deploy -> Manage Deployments -> Select Create New Version for the changes to take effect. For details, please refer to the article above.
⚠️⚠️⚠️Please note, if the Google Apps Script code is changed, you must click Deploy -> Manage Deployments -> Select Create New Version for the changes to take effect. For details, refer to the article above.
Step 3. Register Webhook
Use the Telegram API /setWebhook
to register your Webhook URL.
Request:
1
2
curl --location 'https://api.telegram.org/你的_BOT_API_Token/setWebhook' \
--form 'url="Your Webhook URL"'
Response:
1
2
3
4
5
{
"ok": true,
"result": true,
"description": "Webhook was set"
}
Test
We respond based on different Chat IDs, so we can reply whether it’s a 1:1 chat with the bot or a group chat that includes the bot.
Success 🎉🎉🎉
Next:
Other Google Apps Script Automation Articles
Notes
This is also my 100th article on Medium (first published in October 2018 first article, 6 years ago). I will keep persevering and working hard. I will share detailed insights and data once I reach 1,000 followers (currently 925 as of October 2024) or 1,000,000 total views (currently 984,549 as of October 2024).
If you have any questions or feedback, feel free to contact me.
This post was originally published on Medium (View original post), and automatically converted and synced by ZMediumToMarkdown.