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
Text a drink name or an ingredient to your Telegram chat and the recipe comes straight back. Whenever a new message arrives, the word is looked up on TheCocktailDB as a drink name, and if nothing is called that it is tried as an ingredient, so a word like gin still gets you a drink made with gin.
You get the category, the glass, whether it is alcoholic, the ingredients with their measures, how to make it and the drink's photo, followed by the other drinks that matched and a link to the source page. Every line comes from the record itself: nothing is written by AI, so no ingredient, measure or method is ever invented, and a detail the record lacks is left out. A message too short or too long to be a name gets a prompt asking for a drink or an ingredient, and the bot ignores its own replies.
You need a Telegram bot added to the chat you want answered and a TheCocktailDB connection. Instructions come back in English.
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 1listLimit is greater than 20If listLimit is greater than 20chatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.chatId is emptyIf chatId is emptyqueryText to blank.Set queryText to blank.messageErrorIf a step below fails, save the error as messageErrorincomingMessage.text and save it as queryText.Trim incomingMessage.text and save it as queryText.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 yesqueryText is less than 2If the length of queryText is less than 2chatId.Send a message to chat chatId.Tell me a drink name or an ingredient - 'margarita', or 'gin'.queryText is greater than 60If the length of queryText is greater than 60chatId.Send a message to chat chatId.Tell me a drink name or an ingredient - that message was too long to be either one.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 searchErrorqueryText. Save it as searchResult.Search for queryText. Save it as searchResult.nameMatches to searchResult.drinks.Change nameMatches to searchResult.drinks.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 countErrornameMatches and save it as matchCount.Count the items in nameMatches and save it as matchCount.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 0nameMatches and save it as drink.Get the first item of nameMatches and save it as drink.alternativePool to nameMatches.Change alternativePool to nameMatches.drink is emptyIf drink is emptyingredientMatches to an empty list.Set ingredientMatches to an empty list.filterErrorIf a step below fails, save the error as filterErrorqueryText. Save it as filterResult.List cocktails made with queryText. Save it as filterResult.ingredientMatches to filterResult.drinks.Change ingredientMatches to filterResult.drinks.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 ingredientCountErroringredientMatches and save it as ingredientCount.Count the items in ingredientMatches and save it as ingredientCount.ingredientCount to 0.Change ingredientCount to 0.ingredientCount is greater than 0If ingredientCount is greater than 0alternativePool 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 idErrorfirstMatch.id and save it as firstId.Trim firstMatch.id and save it as firstId.firstId to blank.Change firstId to blank.firstId isn't emptyIf firstId isn't emptylookupErrorIf a step below fails, save the error as lookupErrorfirstId. Save it as drink.Get cocktail firstId. Save it as drink.drink to nothing.Change drink to nothing.drink is emptyIf drink is emptymissText 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 yesmissText 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..chatId.Send a message to chat chatId.missTextdrinkName to blank.Set drinkName to blank.nameErrorIf a step below fails, save the error as nameErrordrink.name and save it as drinkName.Trim drink.name and save it as drinkName.drinkName to blank.Change drinkName to blank.drinkName is emptyIf drinkName is emptychatId.Send a message to chat chatId.I could not read that record - it came back without a drink name.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 categoryErrordrink.category and save it as categoryText.Trim drink.category and save it as categoryText.categoryText to blank.Change categoryText to blank.categoryText isn't emptyIf categoryText isn't emptycategoryText to the end of factLines and save it as factLines.Add Category: categoryText to the end of factLines and save it as factLines.glassText to blank.Set glassText to blank.glassErrorIf a step below fails, save the error as glassErrordrink.glass and save it as glassText.Trim drink.glass and save it as glassText.glassText to blank.Change glassText to blank.glassText isn't emptyIf glassText isn't emptyglassText to the end of factLines and save it as factLines.Add Served in: glassText to the end of factLines and save it as factLines.alcoholicText to blank.Set alcoholicText to blank.alcoholicErrorIf a step below fails, save the error as alcoholicErrordrink.alcoholic and save it as alcoholicText.Trim drink.alcoholic and save it as alcoholicText.alcoholicText to blank.Change alcoholicText to blank.alcoholicText isn't emptyIf alcoholicText isn't emptyalcoholicText to the end of factLines and save it as factLines.Add Classification: alcoholicText to the end of factLines and save it as factLines.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 0factsPart to Change factsPart to
factLines joined by a new line.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 ingredientNameErroringredientRow.name and save it as ingredientName.Trim ingredientRow.name and save it as ingredientName.ingredientName to blank.Change ingredientName to blank.ingredientName isn't emptyIf ingredientName isn't emptyingredientMeasure to blank.Set ingredientMeasure to blank.measureErrorIf a step below fails, save the error as measureErroringredientRow.measure and save it as ingredientMeasure.Trim ingredientRow.measure and save it as ingredientMeasure.ingredientMeasure to blank.Change ingredientMeasure to blank.ingredientLine to - ingredientName.Set ingredientLine to - ingredientName.ingredientMeasure isn't emptyIf ingredientMeasure isn't emptyingredientLine to - ingredientMeasure ingredientName.Change ingredientLine to - ingredientMeasure ingredientName.ingredientLine to the end of ingredientLines and save it as ingredientLines.Add ingredientLine to the end of ingredientLines and save it as ingredientLines.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 0ingredientsPart to Change ingredientsPart to
Ingredients
ingredientLines joined by a new line.methodText to blank.Set methodText to blank.methodErrorIf a step below fails, save the error as methodErrordrink.instructions and save it as methodText.Trim drink.instructions and save it as methodText.methodText to blank.Change methodText to blank.methodPart to blank.Set methodPart to blank.methodText isn't emptyIf methodText isn't emptymethodPart to Change methodPart to
How to make it
methodText truncated to 1200 characters using ... as the ellipsis (keeping words whole).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 listLimitcandidateName to blank.Set candidateName to blank.candidateErrorIf a step below fails, save the error as candidateErrorcandidate.name and save it as candidateName.Trim candidate.name and save it as candidateName.candidateName to blank.Change candidateName to blank.candidateName isn't emptyIf candidateName isn't emptycandidateName is not drinkNameIf candidateName is not drinkNamecandidateName 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.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 0alternativesPart to Change alternativesPart to
Also matching '@queryText': otherNames joined by , .drinkUrl to blank.Set drinkUrl to blank.urlErrorIf a step below fails, save the error as urlErrordrink.url and save it as drinkUrl.Trim drink.url and save it as drinkUrl.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://creditPart to Change creditPart to
Recipe and photo from TheCocktailDB: drinkUrl.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 photoErrordrink.thumbnail and save it as photoUrl.Trim drink.thumbnail and save it as photoUrl.photoUrl to blank.Change photoUrl to blank.photoUrl doesn't start with https://If photoUrl doesn't start with https://photoUrl to blank.Change photoUrl to blank.photoUrl isn't emptyIf photoUrl isn't emptyphotoErrorIf a step below fails, save the error as photoErrorchatId.Send a photo to chat chatId.
Photo URL: photoUrldrinkName - photo from TheCocktailDB truncated to 900 characters using "..." as the ellipsis (keeping words whole)photoError.Show in the output: Could not send the photo, so only the recipe went out: photoError.chatId.Send a message to chat chatId.replyTextphotoUrl isn't emptyIf photoUrl isn't empty