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

Whenever you message a few words to your Telegram chat, a lost mitten or a dragon scared of the dark, AI writes a short bedtime story for your child by name at their reading level, and a picture of one calm scene is drawn and sent above it. A message too short to name a topic gets a friendly reply asking for one.

The story is written to be read aloud: short sentences, words a child of that age knows, and a calm, sleepy ending. The instructions rule out anything frightening, nobody lost or left alone, no unfriendly creatures, no sad ending, and no real people, brands or places. The picture is drawn from a scene the story itself describes and hosted so Telegram can fetch it. If any part of that fails the story is still sent as text, so a run either shows a real picture or none. Its own story messages are recognized and ignored.

You need a Telegram bot in your chat, the child's name and age, and an image generator and an image host connected.

TelegramTelegramWhen a new message is received. Save it as incomingMessage.When a new message is received. Save it as incomingMessage.
Set listenerName to blank.Set listenerName to blank.
Set listenerAge to “5”.Set listenerAge to “5”.
Set ageInYears to listenerAge multiplied by 1.Set ageInYears to listenerAge multiplied by 1.
If ageInYears is less than 2If ageInYears is less than 2
Yes
Stop 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
If ageInYears is greater than 12If ageInYears is greater than 12
Yes
Stop 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
Set chatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.
If chatId is emptyIf chatId is empty
Yes
Stop 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
Set storyTopic to blank.Set storyTopic to blank.
If a step below fails, save the error as messageErrorIf a step below fails, save the error as messageError
Try
Trim incomingMessage.text and save it as storyTopic.Trim incomingMessage.text and save it as storyTopic.
On error
Finish 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.
If storyTopic starts with “Here is tonight's story”If storyTopic starts with “Here is tonight's story”
Yes
Finish 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
If 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.
Finish 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
Shorten 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.
Set 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.
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.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.
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.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.
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.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.
Set storyPrompt to promptRole@promptSafety@promptStyle@promptPictureTonight's story is about: cappedTopicSet storyPrompt to promptRole@promptSafety@promptStyle@promptPictureTonight's story is about: cappedTopic .
Set modelResult to nothing.Set modelResult to nothing.
If 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
Change modelResult to nothing.Change modelResult to nothing.
Set storyRaw to blank.Set storyRaw to blank.
If a step below fails, save the error as storyErrorIf a step below fails, save the error as storyError
Try
Trim modelResult.response_text and save it as storyRaw.Trim modelResult.response_text and save it as storyRaw.
On error
Change storyRaw to blank.Change storyRaw to blank.
If 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.
Finish 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
Set storyText to storyRaw.Set storyText to storyRaw.
Set sceneDescription to cappedTopic.Set sceneDescription to cappedTopic.
If storyRaw contains “ PICTURE:”If storyRaw contains “ PICTURE:”
Yes
Split storyRaw by "Split storyRaw by “ PICTURE:” and save it as storyParts.
Trim the first item of storyParts and save it as storyText.Trim the first item of storyParts and save it as storyText.
Trim the last item of storyParts and save it as scenePart.Trim the last item of storyParts and save it as scenePart.
If scenePart isn't emptyIf scenePart isn't empty
Yes
Change sceneDescription to scenePart.Change sceneDescription to scenePart.
No
No steps
No
No steps
If storyText is emptyIf storyText is empty
Yes
Change storyText to storyRaw.Change storyText to storyRaw.
No
No steps
Set illustrationPrompt to “A gentle children's storybook illustration, soft warm colors, 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 colors, 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 pictureRef to blank.Set pictureRef to blank.
If 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
Trim generated.document_ref and save it as pictureRef.Trim generated.document_ref and save it as pictureRef.
On error
Change pictureRef to blank.Change pictureRef to blank.
Set pictureUrl to blank.Set pictureUrl to blank.
If pictureRef isn't emptyIf pictureRef isn't empty
Yes
If 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.
Trim hosted.url and save it as pictureUrl.Trim hosted.url and save it as pictureUrl.
On error
Change pictureUrl to blank.Change pictureUrl to blank.
No
No steps
If pictureUrl doesn't start with “https://”If pictureUrl doesn't start with “https://”
Yes
Change pictureUrl to blank.Change pictureUrl to blank.
No
No steps
If 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
Set 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
If pictureUrl is emptyIf pictureUrl is empty
Yes
Finish 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
Finish the run: The story was sent with its picture.Finish the run: The story was sent with its picture.