Message a topic to your Telegram chat and get back a gentle bedtime story written for your child, with a picture to go with it.

UsesImgBBOpenAIStability AITelegram

Send a topic to Telegram, get an illustrated bedtime story

TelegramTelegramWhen a new message is received. Save it as incomingMessage.When a new message is received. Save it as incomingMessage.
ValuesSet listenerName to blank.Set listenerName to blank.
ValuesSet listenerAge to 5.Set listenerAge to 5.
MathSet ageInYears to listenerAge multiplied by 1.Set ageInYears to listenerAge multiplied by 1.
Decisions & LoopsIf ageInYears is less than 2If ageInYears is less than 2
Yes
Decisions & LoopsStop and report a problem: Set the 'listenerAge' step to the child's age in years, a whole number from 2 to 12.Stop and report a problem: Set the 'listenerAge' step to the child's age in years, a whole number from 2 to 12.
No
No steps
Decisions & LoopsIf ageInYears is greater than 12If ageInYears is greater than 12
Yes
Decisions & LoopsStop and report a problem: Set the 'listenerAge' step to 12 or under - these stories are written for young children.Stop and report a problem: Set the 'listenerAge' step to 12 or under - these stories are written for young children.
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 send the story.Stop and report a problem: That message did not say which chat it came from, so there was nowhere to send the story.
No
No steps
ValuesSet storyTopic to blank.Set storyTopic 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 storyTopic.Trim incomingMessage.text and save it as storyTopic.
On error
Decisions & LoopsFinish the run: That message had no text in it, so there was no topic to write about.Finish the run: That message had no text in it, so there was no topic to write about.
Decisions & LoopsIf storyTopic starts with Here is tonight's storyIf storyTopic starts with Here is tonight's story
Yes
Decisions & LoopsFinish the run: That message was a story this workflow already sent, so it was left alone.Finish the run: That message was a story this workflow already sent, so it was left alone.
No
No steps
Decisions & LoopsIf the length of storyTopic is less than 3If the length of storyTopic is less than 3
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.Tell me what tonight's story should be about - a lost mitten, a dragon who is scared of the dark, anything at all.
Decisions & LoopsFinish the run: The message did not name a topic, so no story was written.Finish the run: The message did not name a topic, so no story was written.
No
No steps
TextShorten storyTopic to 300 characters (keeping words whole) and save it as cappedTopic.Shorten storyTopic to 300 characters (keeping words whole) and save it as cappedTopic.
ValuesSet promptRole to Write a bedtime story to be read aloud to a child at the end of the day.Set promptRole to Write a bedtime story to be read aloud to a child at the end of the day. It is for listenerName, who is ageInYears years old. Put listenerName in the story as a character.
ValuesSet promptSafety to Keep it gentle. Nothing frightening, no peril, no violence, no injury, no illness, no death, no one lost or left alone for long, and no creature that is not friendly by the end.Set promptSafety to Keep it gentle. Nothing frightening, no peril, no violence, no injury, no illness, no death, no one lost or left alone for long, and no creature that is not friendly by the end. No romance. No real people, real brands or real places. Nothing a grown-up would have to explain, and nothing sad at the end.
ValuesSet promptStyle to Short sentences and words a child of that age knows. About 350 words. Plain text with no formatting marks. Finish on a calm, sleepy note.Set promptStyle to Short sentences and words a child of that age knows. About 350 words. Plain text with no formatting marks. Finish on a calm, sleepy note.
ValuesSet promptPicture to After the story, on its own last line, write PICTURE: followed by one sentence describing a single calm scene from the story that could be drawn. Describe only what is in the picture, and keep it as gentle as the story.Set promptPicture to After the story, on its own last line, write PICTURE: followed by one sentence describing a single calm scene from the story that could be drawn. Describe only what is in the picture, and keep it as gentle as the story.
ValuesSet storyPrompt to promptRole@promptSafety@promptStyle@promptPictureTonight's story is about: cappedTopicSet storyPrompt to promptRole@promptSafety@promptStyle@promptPictureTonight's story is about: cappedTopic .
ValuesSet modelResult to nothing.Set modelResult to nothing.
Decisions & LoopsIf a step below fails, save the error as modelCallErrorIf a step below fails, save the error as modelCallError
Try
OpenAIOpenAIAsk OpenAI: storyPrompt. Save it as modelResult.Ask OpenAI: storyPrompt. Save it as modelResult.
On error
ValuesChange modelResult to nothing.Change modelResult to nothing.
ValuesSet storyRaw to blank.Set storyRaw to blank.
Decisions & LoopsIf a step below fails, save the error as storyErrorIf a step below fails, save the error as storyError
Try
TextTrim modelResult.response_text and save it as storyRaw.Trim modelResult.response_text and save it as storyRaw.
On error
ValuesChange storyRaw to blank.Change storyRaw to blank.
Decisions & LoopsIf storyRaw is emptyIf storyRaw is empty
Yes
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.I could not write a story about that tonight. Send me the idea again and I will try once more.
Decisions & LoopsFinish the run: The model returned nothing, so no story was sent.Finish the run: The model returned nothing, so no story was sent.
No
No steps
ValuesSet storyText to storyRaw.Set storyText to storyRaw.
ValuesSet sceneDescription to cappedTopic.Set sceneDescription to cappedTopic.
Decisions & LoopsIf storyRaw contains PICTURE:If storyRaw contains PICTURE:
Yes
TextSplit storyRaw by "Split storyRaw by PICTURE: and save it as storyParts.
TextTrim the first item of storyParts and save it as storyText.Trim the first item of storyParts and save it as storyText.
TextTrim the last item of storyParts and save it as scenePart.Trim the last item of storyParts and save it as scenePart.
Decisions & LoopsIf scenePart isn't emptyIf scenePart isn't empty
Yes
ValuesChange sceneDescription to scenePart.Change sceneDescription to scenePart.
No
No steps
No
No steps
Decisions & LoopsIf storyText is emptyIf storyText is empty
Yes
ValuesChange storyText to storyRaw.Change storyText to storyRaw.
No
No steps
ValuesSet illustrationPrompt to A gentle children's storybook illustration, soft warm colours, friendly and calm, suitable for a young child, with no text or lettering anywhere in the picture. The scene: sceneDescription truncated to 500 characters using ... as the ellipsis (keeping words whole).Set illustrationPrompt to A gentle children's storybook illustration, soft warm colours, friendly and calm, suitable for a young child, with no text or lettering anywhere in the picture. The scene: sceneDescription truncated to 500 characters using ... as the ellipsis (keeping words whole).
ValuesSet pictureRef to blank.Set pictureRef to blank.
Decisions & LoopsIf a step below fails, save the error as drawingErrorIf a step below fails, save the error as drawingError
Try
Stability AIStability AIGenerate an image of illustrationPrompt. Save it as generated.Generate an image of illustrationPrompt. Save it as generated.text, letters, words, watermark, frightening, dark, scary
TextTrim generated.document_ref and save it as pictureRef.Trim generated.document_ref and save it as pictureRef.
On error
ValuesChange pictureRef to blank.Change pictureRef to blank.
ValuesSet pictureUrl to blank.Set pictureUrl to blank.
Decisions & LoopsIf pictureRef isn't emptyIf pictureRef isn't empty
Yes
Decisions & LoopsIf a step below fails, save the error as hostingErrorIf a step below fails, save the error as hostingError
Try
ImgBBImgBBUpload an image. Save it as hosted.Upload an image. Save it as hosted.
TextTrim hosted.url and save it as pictureUrl.Trim hosted.url and save it as pictureUrl.
On error
ValuesChange pictureUrl to blank.Change pictureUrl to blank.
No
No steps
Decisions & LoopsIf pictureUrl doesn't start with https://If pictureUrl doesn't start with https://
Yes
ValuesChange pictureUrl to blank.Change pictureUrl to blank.
No
No steps
Decisions & LoopsIf pictureUrl isn't emptyIf pictureUrl isn't empty
Yes
TelegramTelegramSend a photo to chat chatId.Send a photo to chat chatId. Photo URL: pictureUrlTonight's story for listenerName: cappedTopic truncated to 900 characters using "..." as the ellipsis (keeping words whole)
No
No steps
ValuesSet storyMessage to Here is tonight's story, listenerName.Set storyMessage to Here is tonight's story, listenerName. storyText truncated to 3600 characters using ... as the ellipsis (keeping words whole).
TelegramTelegramSend a message to chat chatId.Send a message to chat chatId.storyMessage
Decisions & LoopsIf pictureUrl is emptyIf pictureUrl is empty
Yes
Decisions & LoopsFinish the run: The story was sent as text - no picture could be made for it this time.Finish the run: The story was sent as text - no picture could be made for it this time.
No
Decisions & LoopsFinish the run: The story was sent with its picture.Finish the run: The story was sent with its picture.