Text a drink name or an ingredient to your Telegram chat and get the recipe back, with the drink's photo.
Uses
Telegram
TheCocktailDB
Look up a drink from Telegram
incomingMessage.When a new message is received. Save it as incomingMessage.alternativesToList to 5.Set alternativesToList to 5.listLimit to alternativesToList multiplied by 1.Set listLimit to alternativesToList multiplied by 1.listLimit is less than 1If listLimit is less than 1Yes
No
No steps
listLimit is greater than 20If listLimit is greater than 20Yes
No
No steps
chatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.chatId is emptyIf chatId is emptyYes
No
No steps
queryText to blank.Set queryText to blank.messageErrorIf a step below fails, save the error as messageErrorTry
incomingMessage.text and save it as queryText.Trim incomingMessage.text and save it as queryText.On error
isOwnReply to queryText starts with Here is the recipe for or queryText starts with I could not or queryText starts with Tell me a drink name.Set isOwnReply to queryText starts with Here is the recipe for or queryText starts with I could not or queryText starts with Tell me a drink name.isOwnReply is yesIf isOwnReply is yesYes
No
No steps
queryText is less than 2If the length of queryText is less than 2Yes
chatId.Send a message to chat chatId.Tell me a drink name or an ingredient - 'margarita', or 'gin'.No
No steps
queryText is greater than 60If the length of queryText is greater than 60Yes
chatId.Send a message to chat chatId.Tell me a drink name or an ingredient - that message was too long to be either one.No
No steps
lookupFailed to false.Set lookupFailed to false.nameMatches to an empty list.Set nameMatches to an empty list.searchErrorIf a step below fails, save the error as searchErrorTry
queryText. Save it as searchResult.Search for queryText. Save it as searchResult.nameMatches to searchResult.drinks.Change nameMatches to searchResult.drinks.On error
lookupFailed to true.Change lookupFailed to true.nameMatches to an empty list.Change nameMatches to an empty list.matchCount to 0.Set matchCount to 0.countErrorIf a step below fails, save the error as countErrorTry
nameMatches and save it as matchCount.Count the items in nameMatches and save it as matchCount.On error
matchCount to 0.Change matchCount to 0.drink to nothing.Set drink to nothing.alternativePool to an empty list.Set alternativePool to an empty list.matchCount is greater than 0If matchCount is greater than 0Yes
nameMatches and save it as drink.Get the first item of nameMatches and save it as drink.alternativePool to nameMatches.Change alternativePool to nameMatches.No
No steps
drink is emptyIf drink is emptyYes
ingredientMatches to an empty list.Set ingredientMatches to an empty list.filterErrorIf a step below fails, save the error as filterErrorTry
queryText. Save it as filterResult.List cocktails made with queryText. Save it as filterResult.ingredientMatches to filterResult.drinks.Change ingredientMatches to filterResult.drinks.On error
ingredientMatches to an empty list.Change ingredientMatches to an empty list.ingredientCount to 0.Set ingredientCount to 0.ingredientCountErrorIf a step below fails, save the error as ingredientCountErrorTry
ingredientMatches and save it as ingredientCount.Count the items in ingredientMatches and save it as ingredientCount.On error
ingredientCount to 0.Change ingredientCount to 0.ingredientCount is greater than 0If ingredientCount is greater than 0Yes
alternativePool to ingredientMatches.Change alternativePool to ingredientMatches.ingredientMatches and save it as firstMatch.Get the first item of ingredientMatches and save it as firstMatch.firstId to blank.Set firstId to blank.idErrorIf a step below fails, save the error as idErrorTry
firstMatch.id and save it as firstId.Trim firstMatch.id and save it as firstId.On error
firstId to blank.Change firstId to blank.firstId isn't emptyIf firstId isn't emptyYes
lookupErrorIf a step below fails, save the error as lookupErrorTry
firstId. Save it as drink.Get cocktail firstId. Save it as drink.On error
drink to nothing.Change drink to nothing.No
No steps
No
No steps
No
No steps
drink is emptyIf drink is emptyYes
missText to I could not find a drink called '@queryText', or anything made with it.Set missText to I could not find a drink called '@queryText', or anything made with it.lookupFailed is yesIf lookupFailed is yesYes
missText to I could not look that up just now - TheCocktailDB did not answer. Send it again in a moment..Change missText to I could not look that up just now - TheCocktailDB did not answer. Send it again in a moment..No
No steps
chatId.Send a message to chat chatId.missTextNo
No steps
drinkName to blank.Set drinkName to blank.nameErrorIf a step below fails, save the error as nameErrorTry
drink.name and save it as drinkName.Trim drink.name and save it as drinkName.On error
drinkName to blank.Change drinkName to blank.drinkName is emptyIf drinkName is emptyYes
chatId.Send a message to chat chatId.I could not read that record - it came back without a drink name.No
No steps
factLines to an empty list.Set factLines to an empty list.categoryText to blank.Set categoryText to blank.categoryErrorIf a step below fails, save the error as categoryErrorTry
drink.category and save it as categoryText.Trim drink.category and save it as categoryText.On error
categoryText to blank.Change categoryText to blank.categoryText isn't emptyIf categoryText isn't emptyYes
categoryText to the end of factLines and save it as factLines.Add Category: categoryText to the end of factLines and save it as factLines.No
No steps
glassText to blank.Set glassText to blank.glassErrorIf a step below fails, save the error as glassErrorTry
drink.glass and save it as glassText.Trim drink.glass and save it as glassText.On error
glassText to blank.Change glassText to blank.glassText isn't emptyIf glassText isn't emptyYes
glassText to the end of factLines and save it as factLines.Add Served in: glassText to the end of factLines and save it as factLines.No
No steps
alcoholicText to blank.Set alcoholicText to blank.alcoholicErrorIf a step below fails, save the error as alcoholicErrorTry
drink.alcoholic and save it as alcoholicText.Trim drink.alcoholic and save it as alcoholicText.On error
alcoholicText to blank.Change alcoholicText to blank.alcoholicText isn't emptyIf alcoholicText isn't emptyYes
alcoholicText to the end of factLines and save it as factLines.Add Classification: alcoholicText to the end of factLines and save it as factLines.No
No steps
factLines and save it as factCount.Count the items in factLines and save it as factCount.factsPart to blank.Set factsPart to blank.factCount is greater than 0If factCount is greater than 0Yes
factsPart to Change factsPart to
factLines joined by a new line.No
No steps
ingredientLines to an empty list.Set ingredientLines to an empty list.ingredientRow in drink.ingredients:For each ingredientRow in drink.ingredients:ingredientName to blank.Set ingredientName to blank.ingredientNameErrorIf a step below fails, save the error as ingredientNameErrorTry
ingredientRow.name and save it as ingredientName.Trim ingredientRow.name and save it as ingredientName.On error
ingredientName to blank.Change ingredientName to blank.ingredientName isn't emptyIf ingredientName isn't emptyYes
ingredientMeasure to blank.Set ingredientMeasure to blank.measureErrorIf a step below fails, save the error as measureErrorTry
ingredientRow.measure and save it as ingredientMeasure.Trim ingredientRow.measure and save it as ingredientMeasure.On error
ingredientMeasure to blank.Change ingredientMeasure to blank.ingredientLine to - ingredientName.Set ingredientLine to - ingredientName.ingredientMeasure isn't emptyIf ingredientMeasure isn't emptyYes
ingredientLine to - ingredientMeasure ingredientName.Change ingredientLine to - ingredientMeasure ingredientName.No
No steps
ingredientLine to the end of ingredientLines and save it as ingredientLines.Add ingredientLine to the end of ingredientLines and save it as ingredientLines.No
No steps
ingredientLines and save it as ingredientLineCount.Count the items in ingredientLines and save it as ingredientLineCount.ingredientsPart to blank.Set ingredientsPart to blank.ingredientLineCount is greater than 0If ingredientLineCount is greater than 0Yes
ingredientsPart to Change ingredientsPart to
Ingredients
ingredientLines joined by a new line.No
No steps
methodText to blank.Set methodText to blank.methodErrorIf a step below fails, save the error as methodErrorTry
drink.instructions and save it as methodText.Trim drink.instructions and save it as methodText.On error
methodText to blank.Change methodText to blank.methodPart to blank.Set methodPart to blank.methodText isn't emptyIf methodText isn't emptyYes
methodPart to Change methodPart to
How to make it
methodText truncated to 1200 characters using ... as the ellipsis (keeping words whole).No
No steps
otherNames to an empty list.Set otherNames to an empty list.listedCount to 0.Set listedCount to 0.candidate in alternativePool:For each candidate in alternativePool:listedCount is greater than or equal to listLimitIf listedCount is greater than or equal to listLimitYes
No
No steps
candidateName to blank.Set candidateName to blank.candidateErrorIf a step below fails, save the error as candidateErrorTry
candidate.name and save it as candidateName.Trim candidate.name and save it as candidateName.On error
candidateName to blank.Change candidateName to blank.candidateName isn't emptyIf candidateName isn't emptyYes
candidateName is not drinkNameIf candidateName is not drinkNameYes
candidateName to the end of otherNames and save it as otherNames.Add candidateName to the end of otherNames and save it as otherNames.listedCount.Add 1 to listedCount.No
No steps
No
No steps
otherNames and save it as otherCount.Count the items in otherNames and save it as otherCount.alternativesPart to blank.Set alternativesPart to blank.otherCount is greater than 0If otherCount is greater than 0Yes
alternativesPart to Change alternativesPart to
Also matching '@queryText': otherNames joined by , .No
No steps
drinkUrl to blank.Set drinkUrl to blank.urlErrorIf a step below fails, save the error as urlErrorTry
drink.url and save it as drinkUrl.Trim drink.url and save it as drinkUrl.On error
drinkUrl to blank.Change drinkUrl to blank.creditPart to:Set creditPart to:Recipe and photo from TheCocktailDB.drinkUrl starts with https://If drinkUrl starts with https://Yes
creditPart to Change creditPart to
Recipe and photo from TheCocktailDB: drinkUrl.No
No steps
replyTop to Here is the recipe for drinkName.@factsPart.Set replyTop to Here is the recipe for drinkName.@factsPart.replyBody to ingredientsPart plus methodPart.Set replyBody to ingredientsPart plus methodPart.replyTail to alternativesPart plus creditPart.Set replyTail to alternativesPart plus creditPart.replyTop plus replyBody plus replyTail to 3800 characters (keeping words whole) and save it as replyText.Shorten replyTop plus replyBody plus replyTail to 3800 characters (keeping words whole) and save it as replyText.photoUrl to blank.Set photoUrl to blank.photoErrorIf a step below fails, save the error as photoErrorTry
drink.thumbnail and save it as photoUrl.Trim drink.thumbnail and save it as photoUrl.On error
photoUrl to blank.Change photoUrl to blank.photoUrl doesn't start with https://If photoUrl doesn't start with https://Yes
photoUrl to blank.Change photoUrl to blank.No
No steps
photoUrl isn't emptyIf photoUrl isn't emptyYes
photoErrorIf a step below fails, save the error as photoErrorTry
chatId.Send a photo to chat chatId.
Photo URL: photoUrldrinkName - photo from TheCocktailDB truncated to 900 characters using "..." as the ellipsis (keeping words whole)On error
photoError.Show in the output: Could not send the photo, so only the recipe went out: photoError.No
No steps
chatId.Send a message to chat chatId.replyTextphotoUrl isn't emptyIf photoUrl isn't emptyYes
No