Send your Telegram bot a description and it draws that picture and sends it back to the same chat.
Uses
ImgBB
OpenAI
Stability AI
Telegram
Message a description, get a picture back in Telegram
Whenever a message arrives in the chat your Telegram bot watches, the description in it is checked for safety, drawn as a picture in the style and shape you have chosen, and sent back to the same chat as a photo captioned with what was asked for.
The picture goes back only to the chat that asked for it. Every request passes a safety check first: the AI is asked whether the description is one the bot should draw, and a picture is only made on a clear yes. Real or identifiable people, sexual, violent or hateful content, anything meant to pass as a real document or brand, and instructions for making a weapon or a drug are refused, and the chat is told why. If the check does not come back, or the picture cannot be made or hosted, you get a plain message rather than silence. The bot's own replies are recognised and left alone.
Before the first run you need a Telegram bot in the chat, an image generator and an image host, which keeps a public copy for a week so Telegram can fetch it.
incomingMessage.When a new message is received. Save it as incomingMessage.pictureStyle to blank.Set pictureStyle to blank.pictureShape to 1:1.Set pictureShape to 1:1.pictureStyle lowercase and save it as styleChoice.Make pictureStyle lowercase and save it as styleChoice.knownStyles to:Set knownStyles to:3d-model
analog-film
anime
cinematic
comic-book
digital-art
enhance
fantasy-art
isometric
line-art
low-poly
modeling-compound
neon-punk
origami
photographic
pixel-art
...knownStyles doesn't contain styleChoiceIf knownStyles doesn't contain styleChoicepictureShape and save it as shapeChoice.Trim pictureShape and save it as shapeChoice.knownShapes to:Set knownShapes to:1:1
16:9
9:16
3:2
2:3
5:4
4:5
21:9
9:21knownShapes doesn't contain shapeChoiceIf knownShapes doesn't contain shapeChoicechatId to incomingMessage.chat_id.Set chatId to incomingMessage.chat_id.chatId is emptyIf chatId is emptyrequestText to blank.Set requestText to blank.messageErrorIf a step below fails, save the error as messageErrorincomingMessage.text and save it as requestText.Trim incomingMessage.text and save it as requestText.isOwnReply to requestText starts with Here is your picture or requestText starts with I could not draw that or requestText starts with Tell me what to draw.Set isOwnReply to requestText starts with Here is your picture or requestText starts with I could not draw that or requestText starts with Tell me what to draw.isOwnReply is yesIf isOwnReply is yesrequestText is less than 3If the length of requestText is less than 3chatId.Send a message to chat chatId.Tell me what to draw - a red bicycle leaning on a wall at sunset, a fox reading a map, anything you can describe.requestText to 400 characters (keeping words whole) and save it as cappedRequest.Shorten requestText to 400 characters (keeping words whole) and save it as cappedRequest.screenRules to You are the safety check for a picture bot. Someone has sent a description and a picture will be drawn from it. Decide whether it should be drawn.Set screenRules to You are the safety check for a picture bot. Someone has sent a description and a picture will be drawn from it. Decide whether it should be drawn.
Refuse if the description asks for:
- any real, named or otherwise identifiable person, living or dead, including public figures, politicians, celebrities, and anyone the sender says they know
- sexual or suggestive content of anyone, or any depiction of a child that is not ordinary and fully clothed
- violence, gore, injury, self-harm, or a weapon being used on someone
- hateful, demeaning or harassing content about a person or a group
- anything meant to pass as real: an identity document, currency, an official paper, a signature, or the logo or packaging of a real company or product
- a diagram or instructions for making a weapon, an explosive or a drug
Anything else is fine, including invented characters, animals, places, food, objects, patterns, abstract art and fictional scenes.screenPrompt to screenRulesAnswer on one line. Either the single word ALLOW, or REFUSE: followed by one short sentence, beginning with a capital letter, that a person can read and that says what the problem was without repeating the request.Set screenPrompt to screenRulesAnswer on one line. Either the single word ALLOW, or REFUSE: followed by one short sentence, beginning with a capital letter, that a person can read and that says what the problem was without repeating the request.
The description:
cappedRequest
.screenResult to nothing.Set screenResult to nothing.screenCallErrorIf a step below fails, save the error as screenCallErrorscreenPrompt. Save it as screenResult.Ask OpenAI: screenPrompt. Save it as screenResult.screenResult to nothing.Change screenResult to nothing.verdict to blank.Set verdict to blank.verdictErrorIf a step below fails, save the error as verdictErrorscreenResult.response_text and save it as verdict.Trim screenResult.response_text and save it as verdict.verdict to blank.Change verdict to blank.verdict doesn't start with ALLOWIf verdict doesn't start with ALLOWrefusalText to I could not draw that. The safety check did not come back, so nothing was drawn. Send the description again in a moment..Set refusalText to I could not draw that. The safety check did not come back, so nothing was drawn. Send the description again in a moment..verdict starts with REFUSEIf verdict starts with REFUSEverdict with REFUSE: replaced by with REFUSE replaced by and save it as refusalReason.Trim verdict with REFUSE: replaced by with REFUSE replaced by and save it as refusalReason.refusalText to I could not draw that. It is outside what this bot will draw..Change refusalText to I could not draw that. It is outside what this bot will draw..refusalReason isn't emptyIf refusalReason isn't emptyrefusalText to I could not draw that. refusalReason truncated to 300 characters using ... as the ellipsis (keeping words whole).Change refusalText to I could not draw that. refusalReason truncated to 300 characters using ... as the ellipsis (keeping words whole).chatId.Send a message to chat chatId.refusalTextpictureRef to blank.Set pictureRef to blank.drawingErrorIf a step below fails, save the error as drawingErrorcappedRequest. Save it as generated.Generate an image of cappedRequest. Save it as generated.text, letters, words, watermark, signature, logo, brand mark, real person, celebrity, nudity, goregenerated.document_ref and save it as pictureRef.Trim generated.document_ref and save it as pictureRef.pictureRef to blank.Change pictureRef to blank.pictureUrl to blank.Set pictureUrl to blank.pictureRef isn't emptyIf pictureRef isn't emptyhostingErrorIf a step below fails, save the error as hostingErrorhosted.Upload an image. Save it as hosted.hosted.url and save it as pictureUrl.Trim hosted.url and save it as pictureUrl.pictureUrl to blank.Change pictureUrl to blank.pictureUrl doesn't start with https://If pictureUrl doesn't start with https://pictureUrl to blank.Change pictureUrl to blank.pictureUrl isn't emptyIf pictureUrl isn't emptychatId.Send a photo to chat chatId.
Photo URL: pictureUrlHere is your picture: cappedRequest truncated to 900 characters using "..." as the ellipsis (keeping words whole)chatId.Send a message to chat chatId.I could not draw that right now - the picture could not be made. Send the description again in a moment.