Add, list and tick off Google Tasks by sending /add, /list and /done to your Telegram bot.
Uses
Google Tasks
Telegram
Run your Google Tasks list from Telegram
incomingMessage.When a new message is received. Save it as incomingMessage.taskListName to blank.Set taskListName to blank.maxTasksListed to 20.Set maxTasksListed to 20.messageText to blank.Set messageText to blank.noTextErrorIf a step below fails, save the error as noTextErrorTry
incomingMessage.text and save it as messageText.Trim incomingMessage.text and save it as messageText.On error
No steps
messageText is emptyIf messageText is emptyYes
No
No steps
messageText doesn't start with /If messageText doesn't start with /Yes
No
No steps
chatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.messageText by a space and save it as words.Split messageText by a space and save it as words.words and save it as firstWord.Get the first item of words and save it as firstWord.firstWord split by @ lowercase and save it as command.Make the first item of firstWord split by @ lowercase and save it as command./ with in command and save it as verb.Replace / with in command and save it as verb.words joined by a space and save it as commandArgument.Trim the items from index 1 onward of words joined by a space and save it as commandArgument.isKnownCommand to verb is add or verb is list or verb is done.Set isKnownCommand to verb is add or verb is list or verb is done.isKnownCommand is noIf isKnownCommand is noYes
helpIntro to:Set helpIntro to:I look after your Google Tasks list. Send me one of these:helpAdd to:Set helpAdd to:/add Call the dentist
adds a taskhelpList to:Set helpList to:/list
shows what is still open, with each task's IDhelpDone to:Set helpDone to:/done Call the dentist
ticks off the open task with exactly that namehelpNote to If two open tasks share a name I will not guess between them - send /done with the ID from /list instead..Set helpNote to If two open tasks share a name I will not guess between them - send /done with the ID from /list instead..helpText to helpIntro plus helpAdd plus helpList plus helpDone plus helpNote.Set helpText to helpIntro plus helpAdd plus helpList plus helpDone plus helpNote.chatId.Send a message to chat chatId.helpTextNo
No steps
taskListsResult.List lists. Save it as taskListsResult.taskLists to taskListsResult.task_lists.Set taskLists to taskListsResult.task_lists.taskListName lowercase and save it as wantedList.Make taskListName lowercase and save it as wantedList.taskListId to blank.Set taskListId to blank.knownListNames to an empty list.Set knownListNames to an empty list.taskList in taskLists:For each taskList in taskLists:candidateListName to blank.Set candidateListName to blank.listNameErrorIf a step below fails, save the error as listNameErrorTry
taskList.title and save it as candidateListName.Trim taskList.title and save it as candidateListName.On error
No steps
candidateListName isn't emptyIf candidateListName isn't emptyYes
candidateListName to the end of knownListNames and save it as knownListNames.Add candidateListName to the end of knownListNames and save it as knownListNames.candidateListName in lowercase is wantedList and taskListId is emptyIf candidateListName in lowercase is wantedList and taskListId is emptyYes
listIdErrorIf a step below fails, save the error as listIdErrorTry
taskList.id and save it as taskListId.Trim taskList.id and save it as taskListId.On error
No steps
No
No steps
No
No steps
taskListId is emptyIf taskListId is emptyYes
knownListNames with , and save it as knownLists.Join knownListNames with , and save it as knownLists.noListText to I could not find a Google Tasks list called '@taskListName'. The lists on this account are: knownLists.Set noListText to I could not find a Google Tasks list called '@taskListName'. The lists on this account are: knownLists.chatId.Send a message to chat chatId.noListTextNo
No steps
verb is addIf verb is addYes
commandArgument is emptyIf commandArgument is emptyYes
chatId.Send a message to chat chatId.Send the task after the command, like this:
/add Call the dentistNo
commandArgument in Google Tasks list taskListId.Create task commandArgument in Google Tasks list taskListId.addedText to Added to taskListName: commandArgument.Set addedText to Added to taskListName: commandArgument.chatId.Send a message to chat chatId.addedTextNo
No steps
verb is listIf verb is listYes
taskListId. Save it as openTasksResult.List tasks in Google Tasks list taskListId. Save it as openTasksResult.openTasks to openTasksResult.tasks.Set openTasks to openTasksResult.tasks.openTaskCount to 0.Set openTaskCount to 0.openCountErrorIf a step below fails, save the error as openCountErrorTry
openTasks and save it as openTaskCount.Count the items in openTasks and save it as openTaskCount.On error
No steps
taskLines to an empty list.Set taskLines to an empty list.listedCount to 0.Set listedCount to 0.task in openTasks:For each task in openTasks:listedCount multiplied by 1 is greater than or equal to maxTasksListed… If listedCount multiplied by 1 is greater than or equal to maxTasksListed…Yes
No
No steps
lineId to blank. Set lineId to blank.lineIdError If a step below fails, save the error as lineIdErrorTry
task.id and save it as lineId.Trim task.id and save it as lineId.On error
No steps
lineTitle to blank. Set lineTitle to blank.lineTitleError If a step below fails, save the error as lineTitleErrorTry
task.title and save it as lineTitle.Trim task.title and save it as lineTitle.On error
No steps
lineId isn't empty If lineId isn't emptyYes
lineTitle is emptyIf lineTitle is emptyYes
lineTitle to (this task has no title).Change lineTitle to (this task has no title).No
No steps
lineTitleAdd lineTitle
ID: lineId to the end of taskLines and save it as taskLines.listedCount.Add 1 to listedCount.No
No steps
taskLines is emptyIf taskLines is emptyYes
nothingOpenText to Nothing is open in taskListName right now.Set nothingOpenText to Nothing is open in taskListName right now.chatId.Send a message to chat chatId.nothingOpenTextNo
listHeading to Open in taskListName:Set listHeading to Open in taskListName:
.taskLines with a blank line and save it as listBody.Join taskLines with a blank line and save it as listBody.listFooter to blank.Set listFooter to blank.openTaskCount multiplied by 1 is greater than listedCount multiplied by 1If openTaskCount multiplied by 1 is greater than listedCount multiplied by 1Yes
listFooter to Change listFooter to
Showing the first listedCount of openTaskCount open tasks.No
No steps
listText to listHeading plus listBody plus listFooter.Set listText to listHeading plus listBody plus listFooter.chatId.Send a message to chat chatId.listTextNo
No steps
verb is doneIf verb is doneYes
commandArgument is emptyIf commandArgument is emptyYes
chatId.Send a message to chat chatId.Say which task to tick off, like this:
/done Call the dentist
Or send /done with the task's ID from /list.No
taskListId. Save it as candidateResult.List tasks in Google Tasks list taskListId. Save it as candidateResult.candidateTasks to candidateResult.tasks.Set candidateTasks to candidateResult.tasks.commandArgument lowercase and save it as wantedTask.Make commandArgument lowercase and save it as wantedTask.matchedIds to an empty list.Set matchedIds to an empty list.matchedTitles to an empty list.Set matchedTitles to an empty list.candidate in candidateTasks:For each candidate in candidateTasks:candidateId to blank. Set candidateId to blank.candidateIdError If a step below fails, save the error as candidateIdErrorTry
candidate.id and save it as candidateId.Trim candidate.id and save it as candidateId.On error
No steps
candidateTitle to blank. Set candidateTitle to blank.candidateTitleError If a step below fails, save the error as candidateTitleErrorTry
candidate.title and save it as candidateTitle.Trim candidate.title and save it as candidateTitle.On error
No steps
candidateId isn't empty If candidateId isn't emptyYes
idMatches to candidateId is commandArgument.Set idMatches to candidateId is commandArgument.titleMatches to the length of candidateTitle is greater than 0 and candidateTitle in lowercase is wantedTask.Set titleMatches to the length of candidateTitle is greater than 0 and candidateTitle in lowercase is wantedTask.idMatches is yes or titleMatches is yesIf idMatches is yes or titleMatches is yesYes
candidateId to the end of matchedIds and save it as matchedIds.Add candidateId to the end of matchedIds and save it as matchedIds.candidateTitle to the end of matchedTitles and save it as matchedTitles.Add candidateTitle to the end of matchedTitles and save it as matchedTitles.No
No steps
No
No steps
matchedIds is emptyIf matchedIds is emptyYes
noMatchText to Nothing open in taskListName is called '@commandArgument', so nothing was ticked off. Send /list to see what is open.Set noMatchText to Nothing open in taskListName is called '@commandArgument', so nothing was ticked off. Send /list to see what is open.chatId.Send a message to chat chatId.noMatchTextNo
No steps
matchedIds is greater than 1If the length of matchedIds is greater than 1Yes
matchedIds with "Join matchedIds with
ID: and save it as ambiguousIds.ambiguousIntro to More than one open task is called '@commandArgument', so nothing was ticked off.Set ambiguousIntro to More than one open task is called '@commandArgument', so nothing was ticked off.ambiguousText to ambiguousIntro Send /done with one of these IDs instead:Set ambiguousText to ambiguousIntro Send /done with one of these IDs instead:
ID: ambiguousIds.chatId.Send a message to chat chatId.ambiguousTextNo
No steps
matchedIds is 1If the length of matchedIds is 1Yes
matchedIds and save it as targetId.Get the first item of matchedIds and save it as targetId.matchedTitles and save it as targetTitle.Get the first item of matchedTitles and save it as targetTitle.targetTitle is emptyIf targetTitle is emptyYes
targetTitle to targetId.Change targetTitle to targetId.No
No steps
targetId in Google Tasks list taskListId.Complete task targetId in Google Tasks list taskListId.doneText to Ticked off: targetTitle.Set doneText to Ticked off: targetTitle.chatId.Send a message to chat chatId.doneTextNo
No steps
No
No steps