{"id":26655631,"url":"https://github.com/gramiojs/prompt","last_synced_at":"2025-03-25T06:36:46.431Z","repository":{"id":227514408,"uuid":"771640694","full_name":"gramiojs/prompt","owner":"gramiojs","description":"Prompt plugin for GramIO","archived":false,"fork":false,"pushed_at":"2024-08-30T18:33:44.000Z","size":107,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-09-01T10:55:22.155Z","etag":null,"topics":["gramio","gramio-plugin","prompt","question-answering","telegram","telegram-bot-api","telegram-framework"],"latest_commit_sha":null,"homepage":"https://gramio.netlify.app/plugins/official/prompt.html","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gramiojs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-13T17:12:03.000Z","updated_at":"2024-08-30T18:32:36.000Z","dependencies_parsed_at":"2024-05-19T18:25:58.619Z","dependency_job_id":"882fd373-0968-4222-9f47-b0ee4002e2d8","html_url":"https://github.com/gramiojs/prompt","commit_stats":null,"previous_names":["gramiojs/prompt"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gramiojs%2Fprompt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gramiojs%2Fprompt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gramiojs%2Fprompt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gramiojs%2Fprompt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gramiojs","download_url":"https://codeload.github.com/gramiojs/prompt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245414531,"owners_count":20611364,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gramio","gramio-plugin","prompt","question-answering","telegram","telegram-bot-api","telegram-framework"],"created_at":"2025-03-25T06:36:45.931Z","updated_at":"2025-03-25T06:36:46.425Z","avatar_url":"https://github.com/gramiojs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @gramio/prompt\n\n[![npm](https://img.shields.io/npm/v/@gramio/prompt?logo=npm\u0026style=flat\u0026labelColor=000\u0026color=3b82f6)](https://www.npmjs.org/package/@gramio/prompt)\n[![JSR](https://jsr.io/badges/@gramio/prompt)](https://jsr.io/@gramio/prompt)\n[![JSR Score](https://jsr.io/badges/@gramio/prompt/score)](https://jsr.io/@gramio/prompt)\n\nA plugin for [GramIO](https://gramio.dev/) that provides [Prompt](#prompt) and [Wait](#wait) methods\n\nRead about [Plugin options](https://jsr.io/@gramio/prompt@0.1.0/doc/~/prompt#parameters)\n\n## Usage\n\n```ts\nimport { Bot, format, bold } from \"gramio\";\nimport { prompt } from \"@gramio/prompt\";\n\nconst bot = new Bot(process.env.TOKEN as string)\n    .extend(prompt())\n    .command(\"start\", async (context) =\u003e {\n        const answer = await context.prompt(\n            \"message\",\n            format`What's your ${bold`name`}?`\n        );\n\n        return context.send(`✨ Your name is ${answer.text}`);\n    })\n    .onStart(console.log);\n\nbot.start();\n```\n\n## Prompt\n\n### Prompt with text + params\n\n```ts\nconst answer = await context.prompt(\"What's your name?\");\n// or with SendMessageParams\nconst answer = await context.prompt(\"True or false?\", {\n    reply_markup: new Keyboard().text(\"true\").row().text(\"false\"),\n});\n```\n\nanswer is `MessageContext` or `CallbackQueryContext`\n\n### Prompt with text + params and the specified event\n\n```ts\nconst answer = await context.prompt(\"message\", \"What's your name?\");\n\nconst answer = await context.prompt(\"callback_query\", \"True or false?\", {\n    reply_markup: new InlineKeyboard()\n        .text(\"true\", \"true\")\n        .row()\n        .text(\"false\", \"false\"),\n});\n```\n\nanswer is `CallbackQueryContext`\n\n### Validation\n\nYou can define a handler in params to validate the user's answer.\nIf handler returns false, the message will be repeated.\n\n```ts\nconst answer = await context.prompt(\n    \"message\",\n    \"Enter a string that contains russian letter\",\n    {\n        validate: (context) =\u003e /[а-яА-Я]/.test(context.text),\n        //... and some SendMessageParams\n    }\n);\n```\n\n### Transform\n\n```ts\nconst name = await context.prompt(\n    \"message\",\n    format`What's your ${bold`name`}?`,\n    {\n        transform: (context) =\u003e context.text || context.caption || \"\",\n    }\n);\n```\n\nname is `string`\n\n## Wait\n\n### Wait for the next event from the user\n\n```ts\nconst answer = await context.wait();\n```\n\nanswer is `MessageContext` or `CallbackQueryContext`\n\n### Wait for the next event from the user ignoring events not listed\n\n```ts\nconst answer = await context.wait(\"message\");\n```\n\nanswer is `CallbackQueryContext`\n\n### Wait for the next event from the user ignoring non validated answers\n\nYou can define a handler in params to validate the user's answer.\nIf handler return `false`, the **message** will be ignored\n\n```ts\nconst answer = await context.wait((context) =\u003e /[а-яА-Я]/.test(context.text));\n// or combine with event\nconst answer = await context.wait(\"message\", (context) =\u003e\n    /[а-яА-Я]/.test(context.text)\n);\n```\n\n### Wait for the next event from the user ignoring non validated answers with transformer\n\nYou can define a handler in params to **transform** the user's answer.\n\n```ts\nconst answer = await context.wait((context) =\u003e /[а-яА-Я]/.test(context.text));\n// or combine with event\nconst answer = await context.wait(\"message\", {\n    validate: (context) =\u003e /[а-яА-Я]/.test(context.text),\n    transform: (context) =\u003e c.text || \"\",\n});\n```\n\nanswer is `string`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgramiojs%2Fprompt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgramiojs%2Fprompt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgramiojs%2Fprompt/lists"}