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.
Uses
ImgBB
OpenAI
Stability AI
Telegram
Send a topic to Telegram, get an illustrated bedtime story
incomingMessage.When a new message is received. Save it as incomingMessage.listenerName to blank.Set listenerName to blank.listenerAge to 5.Set listenerAge to 5.ageInYears to listenerAge multiplied by 1.Set ageInYears to listenerAge multiplied by 1.ageInYears is less than 2If ageInYears is less than 2Yes
No
No steps
ageInYears is greater than 12If ageInYears is greater than 12Yes
No
No steps
chatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.chatId is emptyIf chatId is emptyYes
No
No steps
storyTopic to blank.Set storyTopic to blank.messageErrorIf a step below fails, save the error as messageErrorTry
incomingMessage.text and save it as storyTopic.Trim incomingMessage.text and save it as storyTopic.On error
storyTopic starts with Here is tonight's storyIf storyTopic starts with Here is tonight's storyYes
No
No steps
storyTopic is less than 3If the length of storyTopic is less than 3Yes
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.No
No steps
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.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.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.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.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.storyPrompt to promptRole@promptSafety@promptStyle@promptPictureTonight's story is about: cappedTopicSet storyPrompt to promptRole@promptSafety@promptStyle@promptPictureTonight's story is about: cappedTopic
.modelResult to nothing.Set modelResult to nothing.modelCallErrorIf a step below fails, save the error as modelCallErrorTry
storyPrompt. Save it as modelResult.Ask OpenAI: storyPrompt. Save it as modelResult.On error
modelResult to nothing.Change modelResult to nothing.storyRaw to blank.Set storyRaw to blank.storyErrorIf a step below fails, save the error as storyErrorTry
modelResult.response_text and save it as storyRaw.Trim modelResult.response_text and save it as storyRaw.On error
storyRaw to blank.Change storyRaw to blank.storyRaw is emptyIf storyRaw is emptyYes
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.No
No steps
storyText to storyRaw.Set storyText to storyRaw.sceneDescription to cappedTopic.Set sceneDescription to cappedTopic.storyRaw contains PICTURE:If storyRaw contains PICTURE:Yes
storyRaw by "Split storyRaw by
PICTURE: and save it as storyParts.storyParts and save it as storyText.Trim the first item of storyParts and save it as storyText.storyParts and save it as scenePart.Trim the last item of storyParts and save it as scenePart.scenePart isn't emptyIf scenePart isn't emptyYes
sceneDescription to scenePart.Change sceneDescription to scenePart.No
No steps
No
No steps
storyText is emptyIf storyText is emptyYes
storyText to storyRaw.Change storyText to storyRaw.No
No steps
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).pictureRef to blank.Set pictureRef to blank.drawingErrorIf a step below fails, save the error as drawingErrorTry
illustrationPrompt. Save it as generated.Generate an image of illustrationPrompt. Save it as generated.text, letters, words, watermark, frightening, dark, scarygenerated.document_ref and save it as pictureRef.Trim generated.document_ref and save it as pictureRef.On error
pictureRef to blank.Change pictureRef to blank.pictureUrl to blank.Set pictureUrl to blank.pictureRef isn't emptyIf pictureRef isn't emptyYes
hostingErrorIf a step below fails, save the error as hostingErrorTry
hosted.Upload an image. Save it as hosted.hosted.url and save it as pictureUrl.Trim hosted.url and save it as pictureUrl.On error
pictureUrl to blank.Change pictureUrl to blank.No
No steps
pictureUrl doesn't start with https://If pictureUrl doesn't start with https://Yes
pictureUrl to blank.Change pictureUrl to blank.No
No steps
pictureUrl isn't emptyIf pictureUrl isn't emptyYes
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
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).chatId.Send a message to chat chatId.storyMessagepictureUrl is emptyIf pictureUrl is emptyYes
No