People opt in with /subscribe, their chat is kept in Baserow, and your /announce goes out to all of them at once.

UsesBaserowTelegram

Announce to everyone who subscribed on Telegram

Whenever someone messages your Telegram bot, the workflow looks for one of three commands. A /subscribe sent in a private chat adds that person to a Baserow table, /unsubscribe removes them straight away, and /announce from you sends whatever you typed after it to everyone on the table, each in their own chat with the bot. Any other message is left alone.

Your announcement goes out word for word, with one fixed line under it telling people how to unsubscribe, and no AI touches it. Only you can send one, and only from a direct message, so an /announce typed by anyone else is refused. A /subscribe from a group chat is refused rather than signing up the whole group. A chat stored twice is messaged once, one run reaches a limited number of people, and you get a report saying how many were reached and how many could not be delivered.

Before the first run you need a Telegram bot and a Baserow table with three columns named 'ChatId', 'Name' and 'Subscribed'.

TelegramTelegramWhen a new message is received. Save it as message.When a new message is received. Save it as message.
Set subscriberTableId to blank.Set subscriberTableId to blank.
Set ownerUserId to blank.Set ownerUserId to blank.
Set maxRecipients to 50.Set maxRecipients to 50.
Set recipientCap to maxRecipients multiplied by 1.Set recipientCap to maxRecipients multiplied by 1.
If recipientCap is less than 1If recipientCap is less than 1
Yes
Stop and report a problem: Set 'maxRecipients' to 1 or more - it is the most people one announcement can reach in a single run.Stop and report a problem: Set 'maxRecipients' to 1 or more - it is the most people one announcement can reach in a single run.
No
No steps
Trim message.chat_id and save it as chatId.Trim message.chat_id and save it as chatId.
Trim message.from_user_id and save it as senderId.Trim message.from_user_id and save it as senderId.
Set isDirectMessage to chatId is senderId and senderId is not “null”.Set isDirectMessage to chatId is senderId and senderId is not “null”.
Set messageText to blank.Set messageText to blank.
If a step below fails, save the error as noTextErrorIf a step below fails, save the error as noTextError
Try
Trim message.text and save it as messageText.Trim message.text and save it as messageText.
On error
Show in the output: “This message carried no text, so there was nothing to do.”.Show in the output: “This message carried no text, so there was nothing to do.”.
If messageText is emptyIf messageText is empty
Yes
Finish the run: This message carried no text, so nobody was added, removed or sent to.Finish the run: This message carried no text, so nobody was added, removed or sent to.
No
No steps
Split messageText by a space and save it as words.Split messageText by a space and save it as words.
TextMake the first item of words[0] split by “@” lowercase and save it as command.Make the first item of words[0] split by “@” lowercase and save it as command.
Trim the items from index 1 onward of words joined by a space and save it as rest.Trim the items from index 1 onward of words joined by a space and save it as rest.
If command is not “/subscribe” and command is not “/unsubscribe” and command is…If command is not “/subscribe” and command is not “/unsubscribe” and command is…
Yes
If messageText starts with “/” (ignoring case)If messageText starts with “/” (ignoring case)
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId./subscribe - start getting announcements (message me directly) /unsubscribe - stop getting them
No
No steps
Finish the run: This message was not a /subscribe, /unsubscribe or /announce command, so nobody was added, removed or sent to.Finish the run: This message was not a /subscribe, /unsubscribe or /announce command, so nobody was added, removed or sent to.
No
No steps
Set listPage to nothing.Set listPage to nothing.
Set readFailed to false.Set readFailed to false.
If a step below fails, save the error as readErrorIf a step below fails, save the error as readError
Try
BaserowBaserowList rows in table subscriberTableId. Save it as listPage.List rows in table subscriberTableId. Save it as listPage. Rows per page: 200
On error
Change readFailed to true.Change readFailed to true.
If readFailed is yesIf readFailed is yes
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.I could not reach the subscriber list just now, so nothing was changed and nothing was sent. Try again in a moment.
Stop and report a problem: The subscriber list could not be read.Stop and report a problem: The subscriber list could not be read.
No
No steps
Set storedRows to listPage.results.Set storedRows to listPage.results.
Set storedTotal to listPage.count multiplied by 1.Set storedTotal to listPage.count multiplied by 1.
Set storedIds to an empty list.Set storedIds to an empty list.
Set myRowIds to an empty list.Set myRowIds to an empty list.
For each storedRow in storedRows:For each storedRow in storedRows:
If a step below fails, save the error as rowErrorIf a step below fails, save the error as rowError
Try
Trim storedRow.ChatId and save it as storedId.Trim storedRow.ChatId and save it as storedId.
If storedId isn't empty and storedId is not “null”If storedId isn't empty and storedId is not “null”
Yes
Add storedId to the end of storedIds and save it as storedIds.Add storedId to the end of storedIds and save it as storedIds.
If storedId is senderIdIf storedId is senderId
Yes
Add storedRow.id to the end of myRowIds and save it as myRowIds.Add storedRow.id to the end of myRowIds and save it as myRowIds.
No
No steps
No
No steps
On error
Show in the output: “Skipped a subscriber row with no chat ID in it.”.Show in the output: “Skipped a subscriber row with no chat ID in it.”.
If command is “/subscribe”If command is “/subscribe”
Yes
If isDirectMessage is noIf isDirectMessage is no
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.Message me directly to subscribe - open a one-to-one chat with me and send /subscribe there. Subscribing from a group would sign the whole group up, so I do not do it.
Finish the run: A /subscribe from a group chat was refused.Finish the run: A /subscribe from a group chat was refused.
No
No steps
If myRowIds isn't emptyIf myRowIds isn't empty
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.You are already on the list, so I have not added you again. Send /unsubscribe whenever you want to stop.
Finish the run: That chat was already subscribed.Finish the run: That chat was already subscribed.
No
No steps
Set subscriberName to “unknown”.Set subscriberName to “unknown”.
If a step below fails, save the error as noNameErrorIf a step below fails, save the error as noNameError
Try
Trim message.from_username and save it as subscriberName.Trim message.from_username and save it as subscriberName.
On error
Show in the output: “This subscriber has no Telegram username.”.Show in the output: “This subscriber has no Telegram username.”.
Set joinFailed to false.Set joinFailed to false.
If a step below fails, save the error as joinErrorIf a step below fails, save the error as joinError
Try
BaserowBaserowCreate a row in table subscriberTableId.Create a row in table subscriberTableId.
On error
Change joinFailed to true.Change joinFailed to true.
If joinFailed is yesIf joinFailed is yes
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.I could not add you to the list, so you are not subscribed. Send /subscribe again in a moment.
Stop and report a problem: The subscriber row could not be created.Stop and report a problem: The subscriber row could not be created.
No
No steps
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.You are on the list and will get the announcements. Send /unsubscribe at any time to stop - it takes effect straight away.
Finish the run: Subscribed.Finish the run: Subscribed.
Else if @command is "/unsubscribe"
If myRowIds is emptyIf myRowIds is empty
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.You are not on the list, so there is nothing to stop. You will not get any announcements.
Finish the run: That chat was not subscribed.Finish the run: That chat was not subscribed.
No
No steps
Set removed to 0.Set removed to 0.
Set removeFailed to false.Set removeFailed to false.
For each myRowId in myRowIds:For each myRowId in myRowIds:
If a step below fails, save the error as removeError If a step below fails, save the error as removeError
Try
BaserowBaserowDelete row myRowId from table subscriberTableId.Delete row myRowId from table subscriberTableId.
Add 1 to removed.Add 1 to removed.
On error
Change removeFailed to true.Change removeFailed to true.
If removeFailed is yesIf removeFailed is yes
Yes
If removed is 0If removed is 0
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.I could not take you off the list, so you are still subscribed. Send /unsubscribe again in a moment.
Stop and report a problem: No subscriber row could be deleted.Stop and report a problem: No subscriber row could be deleted.
No
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.I took you off the list, but one of your entries would not delete, so you may still get an announcement. Send /unsubscribe again to clear it.
Stop and report a problem: Only some subscriber rows could be deleted.Stop and report a problem: Only some subscriber rows could be deleted.
No
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.You are off the list. You will not get any more announcements. Send /subscribe if you change your mind.
Finish the run: Unsubscribed.Finish the run: Unsubscribed.
Otherwise
If senderId is not ownerUserId or senderId is “null”If senderId is not ownerUserId or senderId is “null”
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.Only the owner of this list can send an announcement, so nothing was sent.
Finish the run: An /announce from someone other than the owner was refused.Finish the run: An /announce from someone other than the owner was refused.
No
No steps
If isDirectMessage is noIf isDirectMessage is no
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.Send /announce in a direct message to me rather than in a group. Nothing was sent.
Finish the run: An /announce sent from a group chat was refused.Finish the run: An /announce sent from a group chat was refused.
No
No steps
If rest is emptyIf rest is empty
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.Write the announcement after /announce. Nothing was sent.
Finish the run: The /announce command had nothing after it.Finish the run: The /announce command had nothing after it.
No
No steps
Remove duplicates from storedIds and save it as uniqueIds.Remove duplicates from storedIds and save it as uniqueIds.
If uniqueIds is emptyIf uniqueIds is empty
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.Nobody has subscribed yet, so nothing was sent.
Finish the run: The subscriber list is empty.Finish the run: The subscriber list is empty.
No
No steps
Take the first recipientCap items of uniqueIds and save it as recipients.Take the first recipientCap items of uniqueIds and save it as recipients.
Set announcement to restSet announcement to rest --- You are getting this because you subscribed. Send /unsubscribe to stop.
Set sentCount to 0.Set sentCount to 0.
Set failedCount to 0.Set failedCount to 0.
For each recipientId in recipients:For each recipientId in recipients:
If a step below fails, save the error as sendError If a step below fails, save the error as sendError
Try
TelegramTelegramSend a message to chat recipientId.Send a message to chat recipientId.announcement
Add 1 to sentCount.Add 1 to sentCount.
On error
Add 1 to failedCount.Add 1 to failedCount.
Set report to “Sent to sentCount as text of the length of uniqueIds as text subscribers.”.Set report to “Sent to sentCount as text of the length of uniqueIds as text subscribers.”.
If failedCount is greater than 0If failedCount is greater than 0
Yes
Change report to “@report failedCount as text could not be delivered.”.Change report to “@report failedCount as text could not be delivered.”.
No
No steps
If the length of uniqueIds is greater than the length of recipientsIf the length of uniqueIds is greater than the length of recipients
Yes
Change report to “@report The 'maxRecipients' cap stopped it at the length of recipients as text - raise the cap and send it again to reach the rest, but the ones already reached will get it a second time.”.Change report to “@report The 'maxRecipients' cap stopped it at the length of recipients as text - raise the cap and send it again to reach the rest, but the ones already reached will get it a second time.”.
No
No steps
If storedTotal is greater than 200If storedTotal is greater than 200
Yes
Change report to “@report Your table holds more than the 200 rows one read returns, so the rest were not considered.”.Change report to “@report Your table holds more than the 200 rows one read returns, so the rest were not considered.”.
No
No steps
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.report