Answers questions asked in a Telegram chat by searching the web, and replies with the answer and the pages it came from.

UsesOpenAISerperTelegram

Answer Telegram questions from the web, with sources

TelegramTelegramWhen a new message is received. Save it as incomingMessage.When a new message is received. Save it as incomingMessage.
ValuesSet subjectsToAnswer to blank.Set subjectsToAnswer to blank.
ValuesSet sourcesToUse to 3.Set sourcesToUse to 3.
ValuesSet minimumQuestionLength to 12.Set minimumQuestionLength to 12.
MathSet sourcesWanted to sourcesToUse multiplied by 1.Set sourcesWanted to sourcesToUse multiplied by 1.
Decisions & LoopsIf sourcesWanted is less than 1If sourcesWanted is less than 1
Yes
Decisions & LoopsStop and report a problem: Set the 'sourcesToUse' step to how many search results to read - a whole number from 1 to 5.Stop and report a problem: Set the 'sourcesToUse' step to how many search results to read - a whole number from 1 to 5.
No
No steps
Decisions & LoopsIf sourcesWanted is greater than 5If sourcesWanted is greater than 5
Yes
Decisions & LoopsStop and report a problem: Set the 'sourcesToUse' step to 5 or fewer, so the reply fits inside one Telegram message.Stop and report a problem: Set the 'sourcesToUse' step to 5 or fewer, so the reply fits inside one Telegram message.
No
No steps
ValuesSet chatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.
Decisions & LoopsIf chatId is emptyIf chatId is empty
Yes
Decisions & LoopsStop and report a problem: That message did not say which chat it came from, so there was nowhere to reply.Stop and report a problem: That message did not say which chat it came from, so there was nowhere to reply.
No
No steps
ValuesSet question to blank.Set question to blank.
Decisions & LoopsIf a step below fails, save the error as messageErrorIf a step below fails, save the error as messageError
Try
TextTrim incomingMessage.text and save it as question.Trim incomingMessage.text and save it as question.
On error
Decisions & LoopsFinish the run: That message had no text in it, so there was no question to answer.Finish the run: That message had no text in it, so there was no question to answer.
Decisions & LoopsIf question starts with Here is what I foundIf question starts with Here is what I found
Yes
Decisions & LoopsFinish the run: That message was an answer this workflow already sent, so it was left alone.Finish the run: That message was an answer this workflow already sent, so it was left alone.
No
No steps
MathSet questionFloor to minimumQuestionLength multiplied by 1.Set questionFloor to minimumQuestionLength multiplied by 1.
Decisions & LoopsIf the length of question is less than questionFloorIf the length of question is less than questionFloor
Yes
Decisions & LoopsFinish the run: That message was too short to be a question worth searching for.Finish the run: That message was too short to be a question worth searching for.
No
No steps
SerperSerperSearch Google for '@question truncated to 300 characters using as the ellipsis (keeping words whole)'. Save it as searchResult.Search Google for '@question truncated to 300 characters using as the ellipsis (keeping words whole)'. Save it as searchResult.
ValuesSet searchResults to searchResult.results.Set searchResults to searchResult.results.
ListsStart an empty list and save it as citationLines.Start an empty list and save it as citationLines.
ListsStart an empty list and save it as sourceBlocks.Start an empty list and save it as sourceBlocks.
ValuesSet sourceNumber to 0.Set sourceNumber to 0.
Decisions & LoopsFor each row in searchResults:For each row in searchResults:
Decisions & LoopsIf sourceNumber is greater than or equal to sourcesWantedIf sourceNumber is greater than or equal to sourcesWanted
Yes
Decisions & LoopsStop repeating.Stop repeating.
No
No steps
ValuesSet resultLink to blank.Set resultLink to blank.
ValuesSet resultTitle to blank.Set resultTitle to blank.
ValuesSet resultSnippet to blank.Set resultSnippet to blank.
Decisions & LoopsIf a step below fails, save the error as linkErrorIf a step below fails, save the error as linkError
Try
TextTrim row.link and save it as resultLink.Trim row.link and save it as resultLink.
On error
Decisions & LoopsSkip to the next item.Skip to the next item.
Decisions & LoopsIf resultLink is emptyIf resultLink is empty
Yes
Decisions & LoopsSkip to the next item.Skip to the next item.
No
No steps
Decisions & LoopsIf a step below fails, save the error as titleErrorIf a step below fails, save the error as titleError
Try
TextTrim row.title and save it as resultTitle.Trim row.title and save it as resultTitle.
On error
ValuesChange resultTitle to blank.Change resultTitle to blank.
Decisions & LoopsIf resultTitle is emptyIf resultTitle is empty
Yes
ValuesChange resultTitle to Untitled page.Change resultTitle to Untitled page.
No
No steps
Decisions & LoopsIf a step below fails, save the error as snippetErrorIf a step below fails, save the error as snippetError
Try
TextTrim row.snippet and save it as resultSnippet.Trim row.snippet and save it as resultSnippet.
On error
ValuesChange resultSnippet to blank.Change resultSnippet to blank.
ValuesAdd 1 to sourceNumber.Add 1 to sourceNumber.
ListsAdd [sourceNumber] resultTitle truncated to 110 characters using ... as the ellipsisAdd [sourceNumber] resultTitle truncated to 110 characters using ... as the ellipsis resultLink truncated to 200 characters using as the ellipsis to the end of citationLines and save it as citationLines.
ListsAdd [sourceNumber] resultTitleAdd [sourceNumber] resultTitle resultLink resultSnippet truncated to 700 characters using ... as the ellipsis to the end of sourceBlocks and save it as sourceBlocks.
Decisions & LoopsIf citationLines is emptyIf citationLines is empty
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.I searched the web for that but did not get back any result I could cite, so I have not written an answer. Try asking it a different way.
Decisions & LoopsFinish the run: The search returned nothing citable, so no answer was written.Finish the run: The search returned nothing citable, so no answer was written.
No
No steps
ValuesSet promptRole to You are a research assistant answering a question someone asked in a Telegram chat.Set promptRole to You are a research assistant answering a question someone asked in a Telegram chat. This assistant answers questions about: subjectsToAnswer .
ValuesSet promptRules to Rules you must follow:Set promptRules to Rules you must follow: - Answer only from the numbered sources below. Do not use anything else you know. - Never invent a source, a web address, a statistic or a quotation. - Cite by number in square brackets, like [1], after each claim it supports. - Do not write out any web address. The addresses are added below your answer for you.
ValuesSet promptRulesTwo to - If the sources do not answer the question, say plainly that they do not, and say what they do cover.Set promptRulesTwo to - If the sources do not answer the question, say plainly that they do not, and say what they do cover. - If the question is outside the subjects above, say so instead of answering it. - Plain text only, no formatting marks, under 200 words.
ValuesSet promptSources to Sources:Set promptSources to Sources: sourceBlocks joined by a blank line .
ValuesSet answerPrompt to promptRole@promptRules@promptRulesTwo@promptSourcesQuestion:Set answerPrompt to promptRole@promptRules@promptRulesTwo@promptSourcesQuestion: question .
OpenAIOpenAIAsk OpenAI: answerPrompt. Save it as modelResult.Ask OpenAI: answerPrompt. Save it as modelResult.
ValuesSet answerText to blank.Set answerText to blank.
Decisions & LoopsIf a step below fails, save the error as answerErrorIf a step below fails, save the error as answerError
Try
TextTrim modelResult.response_text and save it as answerText.Trim modelResult.response_text and save it as answerText.
On error
ValuesChange answerText to blank.Change answerText to blank.
Decisions & LoopsIf answerText is emptyIf answerText is empty
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.I found sources for that but could not write an answer from them. Here is what the search returned, so you can read it yourself: citationLines joined by a blank line
Decisions & LoopsFinish the run: The model returned no answer, so the sources were sent on their own.Finish the run: The model returned no answer, so the sources were sent on their own.
No
No steps
ValuesSet replyHeader to Here is what I found.Set replyHeader to Here is what I found.
TextShorten answerText to 2400 characters (keeping words whole) and save it as replyBody.Shorten answerText to 2400 characters (keeping words whole) and save it as replyBody.
ValuesSet replySources to Set replySources to Sources: citationLines joined by a blank line.
MathSet replyText to replyHeader plus replyBody plus replySources.Set replyText to replyHeader plus replyBody plus replySources.
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.replyText
Decisions & LoopsFinish the run: The answer was sent, with the pages it was written from listed under it.Finish the run: The answer was sent, with the pages it was written from listed under it.