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
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 1Yes
No
No steps
message.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 noTextErrorTry
message.text and save it as messageText.Trim message.text and save it as messageText.On error
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 emptyYes
No
No steps
messageText 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…Yes
messageText starts with / (ignoring case)If messageText starts with / (ignoring case)Yes
chatId.Send a message to chat chatId./subscribe - start getting announcements (message me directly)
/unsubscribe - stop getting themNo
No steps
No
No steps
listPage to nothing.Set listPage to nothing.readFailed to false.Set readFailed to false.readErrorIf a step below fails, save the error as readErrorTry
subscriberTableId. Save it as listPage.List rows in table subscriberTableId. Save it as listPage.
Rows per page: 200On error
readFailed to true.Change readFailed to true.readFailed is yesIf readFailed is yesYes
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.No
No steps
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 rowErrorTry
storedRow.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 nullYes
storedId 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 senderIdYes
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
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 /subscribeYes
isDirectMessage is noIf isDirectMessage is noYes
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.No
No steps
myRowIds isn't emptyIf myRowIds isn't emptyYes
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.No
No steps
subscriberName to unknown.Set subscriberName to unknown.noNameErrorIf a step below fails, save the error as noNameErrorTry
message.from_username and save it as subscriberName.Trim message.from_username and save it as subscriberName.On error
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 joinErrorTry
subscriberTableId.Create a row in table subscriberTableId.On error
joinFailed to true.Change joinFailed to true.joinFailed is yesIf joinFailed is yesYes
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.No
No steps
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.Else if @command is "/unsubscribe"
myRowIds is emptyIf myRowIds is emptyYes
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.No
No steps
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 removeErrorTry
myRowId from table subscriberTableId.Delete row myRowId from table subscriberTableId.removed.Add 1 to removed.On error
removeFailed to true.Change removeFailed to true.removeFailed is yesIf removeFailed is yesYes
removed is 0If removed is 0Yes
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.No
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.No
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.Otherwise
senderId is not ownerUserId or senderId is nullIf senderId is not ownerUserId or senderId is nullYes
chatId.Send a message to chat chatId.Only the owner of this list can send an announcement, so nothing was sent.No
No steps
isDirectMessage is noIf isDirectMessage is noYes
chatId.Send a message to chat chatId.Send /announce in a direct message to me rather than in a group. Nothing was sent.No
No steps
rest is emptyIf rest is emptyYes
chatId.Send a message to chat chatId.Write the announcement after /announce. Nothing was sent.No
No steps
storedIds and save it as uniqueIds.Remove duplicates from storedIds and save it as uniqueIds.uniqueIds is emptyIf uniqueIds is emptyYes
chatId.Send a message to chat chatId.Nobody has subscribed yet, so nothing was sent.No
No steps
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 sendErrorTry
recipientId.Send a message to chat recipientId.announcementsentCount.Add 1 to sentCount.On error
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 0Yes
report to report failedCount as text could not be delivered.Change report to report failedCount as text could not be delivered.No
No steps
uniqueIds is greater than the length of recipientsIf the length of uniqueIds is greater than the length of recipientsYes
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
storedTotal is greater than 200If storedTotal is greater than 200Yes
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
chatId.Send a message to chat chatId.report