People opt in with /subscribe, their chat is kept in Baserow, and your /announce goes out to all of them at once.
Uses
Baserow
Telegram
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'.
message.When a new message is received. Save it as message.subscriberTableId to blank.Set subscriberTableId to blank.ownerUserId to blank.Set ownerUserId to blank.maxRecipients to 50.Set maxRecipients to 50.recipientCap to maxRecipients multiplied by 1.Set recipientCap to maxRecipients multiplied by 1.recipientCap is less than 1If recipientCap is less than 1message.chat_id and save it as chatId.Trim message.chat_id and save it as chatId.message.from_user_id and save it as senderId.Trim message.from_user_id and save it as senderId.isDirectMessage to chatId is senderId and senderId is not null.Set isDirectMessage to chatId is senderId and senderId is not null.messageText to blank.Set messageText to blank.noTextErrorIf a step below fails, save the error as noTextErrormessage.text and save it as messageText.Trim message.text and save it as messageText.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..messageText is emptyIf messageText is emptymessageText by a space and save it as words.Split messageText by a space and save it as words.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.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.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…messageText starts with / (ignoring case)If messageText starts with / (ignoring case)chatId.Send a message to chat chatId./subscribe - start getting announcements (message me directly)
/unsubscribe - stop getting themlistPage to nothing.Set listPage to nothing.readFailed to false.Set readFailed to false.readErrorIf a step below fails, save the error as readErrorsubscriberTableId. Save it as listPage.List rows in table subscriberTableId. Save it as listPage.
Rows per page: 200readFailed to true.Change readFailed to true.readFailed is yesIf readFailed is yeschatId.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.storedRows to listPage.results.Set storedRows to listPage.results.storedTotal to listPage.count multiplied by 1.Set storedTotal to listPage.count multiplied by 1.storedIds to an empty list.Set storedIds to an empty list.myRowIds to an empty list.Set myRowIds to an empty list.storedRow in storedRows:For each storedRow in storedRows:rowErrorIf a step below fails, save the error as rowErrorstoredRow.ChatId and save it as storedId.Trim storedRow.ChatId and save it as storedId.storedId isn't empty and storedId is not nullIf storedId isn't empty and storedId is not nullstoredId to the end of storedIds and save it as storedIds.Add storedId to the end of storedIds and save it as storedIds.storedId is senderIdIf storedId is senderIdstoredRow.id to the end of myRowIds and save it as myRowIds.Add storedRow.id to the end of myRowIds and save it as myRowIds.Skipped a subscriber row with no chat ID in it..Show in the output: Skipped a subscriber row with no chat ID in it..command is /subscribeIf command is /subscribeisDirectMessage is noIf isDirectMessage is nochatId.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.myRowIds isn't emptyIf myRowIds isn't emptychatId.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.subscriberName to unknown.Set subscriberName to unknown.noNameErrorIf a step below fails, save the error as noNameErrormessage.from_username and save it as subscriberName.Trim message.from_username and save it as subscriberName.This subscriber has no Telegram username..Show in the output: This subscriber has no Telegram username..joinFailed to false.Set joinFailed to false.joinErrorIf a step below fails, save the error as joinErrorsubscriberTableId.Create a row in table subscriberTableId.joinFailed to true.Change joinFailed to true.joinFailed is yesIf joinFailed is yeschatId.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.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.myRowIds is emptyIf myRowIds is emptychatId.Send a message to chat chatId.You are not on the list, so there is nothing to stop. You will not get any announcements.removed to 0.Set removed to 0.removeFailed to false.Set removeFailed to false.myRowId in myRowIds:For each myRowId in myRowIds:removeError If a step below fails, save the error as removeErrormyRowId from table subscriberTableId.Delete row myRowId from table subscriberTableId.removed.Add 1 to removed.removeFailed to true.Change removeFailed to true.removeFailed is yesIf removeFailed is yesremoved is 0If removed is 0chatId.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.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.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.senderId is not ownerUserId or senderId is nullIf senderId is not ownerUserId or senderId is nullchatId.Send a message to chat chatId.Only the owner of this list can send an announcement, so nothing was sent.isDirectMessage is noIf isDirectMessage is nochatId.Send a message to chat chatId.Send /announce in a direct message to me rather than in a group. Nothing was sent.rest is emptyIf rest is emptychatId.Send a message to chat chatId.Write the announcement after /announce. Nothing was sent.storedIds and save it as uniqueIds.Remove duplicates from storedIds and save it as uniqueIds.uniqueIds is emptyIf uniqueIds is emptychatId.Send a message to chat chatId.Nobody has subscribed yet, so nothing was sent.recipientCap items of uniqueIds and save it as recipients.Take the first recipientCap items of uniqueIds and save it as recipients.announcement to restSet announcement to rest
---
You are getting this because you subscribed. Send /unsubscribe to stop.sentCount to 0.Set sentCount to 0.failedCount to 0.Set failedCount to 0.recipientId in recipients:For each recipientId in recipients:sendError If a step below fails, save the error as sendErrorrecipientId.Send a message to chat recipientId.announcementsentCount.Add 1 to sentCount.failedCount.Add 1 to failedCount.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.failedCount is greater than 0If failedCount is greater than 0report to report failedCount as text could not be delivered.Change report to report failedCount as text could not be delivered.uniqueIds is greater than the length of recipientsIf the length of uniqueIds is greater than the length of recipientsreport 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.storedTotal is greater than 200If storedTotal is greater than 200report 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.chatId.Send a message to chat chatId.report