{"id":22733471,"url":"https://github.com/strikeentco/teabot","last_synced_at":"2026-03-16T04:32:47.655Z","repository":{"id":36787182,"uuid":"41093957","full_name":"strikeentco/teabot","owner":"strikeentco","description":":tea: Teabot - right way to build interactive Telegram bots.","archived":false,"fork":false,"pushed_at":"2016-03-27T14:40:35.000Z","size":46,"stargazers_count":17,"open_issues_count":1,"forks_count":7,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T16:04:20.319Z","etag":null,"topics":["bot","framework","javascript","nodejs","teabot","telegram","telegram-bot"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/strikeentco.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}},"created_at":"2015-08-20T12:17:24.000Z","updated_at":"2021-04-27T14:43:44.000Z","dependencies_parsed_at":"2022-08-29T19:11:13.981Z","dependency_job_id":null,"html_url":"https://github.com/strikeentco/teabot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strikeentco%2Fteabot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strikeentco%2Fteabot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strikeentco%2Fteabot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strikeentco%2Fteabot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strikeentco","download_url":"https://codeload.github.com/strikeentco/teabot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248198879,"owners_count":21063627,"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":["bot","framework","javascript","nodejs","teabot","telegram","telegram-bot"],"created_at":"2024-12-10T20:14:43.559Z","updated_at":"2026-03-16T04:32:42.634Z","avatar_url":"https://github.com/strikeentco.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"teabot\n==========\n[![license](https://img.shields.io/github/license/strikeentco/teabot.svg?style=flat)](https://github.com/strikeentco/teabot/blob/master/LICENSE) [![node](https://img.shields.io/node/v/teabot.svg)](https://www.npmjs.com/package/teabot) [![npm](https://img.shields.io/npm/v/teabot.svg?style=flat)](https://www.npmjs.com/package/teabot) [![bitHound Score](https://www.bithound.io/github/strikeentco/teabot/badges/score.svg)](https://www.bithound.io/github/strikeentco/teabot)\n\n`TeaBot` allows you to create highly interactive Telegram bots for Node.js with some additional cool features.\n\n## Features\n* Written for creating interactive bots\n* Supports [plugins](#plugins)\n  * Data storage in Redis, Aerospike ([with plugins](#plugins))\n  * Analytics [botan.io](http://botan.io) ([with plugins](#plugins))\n* Supports [Inline Mode](#inline-mode)\n* Supports `/command@BotName` commands\n* Has own [wrapper](https://github.com/strikeentco/tg-yarl) over Telegram API to enhance existing functionality\n\nDifference between TeaBot `1.x.x` and TeaBot `2.0.0` [here](https://github.com/strikeentco/teabot/tree/master/docs/MIGRATION.md).\n\n# Usage\n\n```sh\n$ npm install teabot --save\n```\n\nSimple echo bot:\n```js\nconst TeaBot = require('teabot')('TELEGRAM_BOT_TOKEN', 'TELEGRAM_BOT_NAME');\n\nTeaBot.defineCommand(function (dialog, message) {\n  dialog.sendMessage('Echo: ' + message.text);\n});\n\nTeaBot.startPolling();\n```\n\n## Quick navigation\n* [Methods](#methods)\n  * [Start methods](#start-methods)\n  * [Dialog object](#dialog-object)\n  * [Message object](#message-object)\n  * [Commands](#commands)\n  * [Actions](#actions)\n  * [Inline mode](#inline-mode)\n  * [Plugins](#plugins)\n  * [Errors](#errors)\n* [Documentation](#documentation)\n* [Examples](#examples)\n\n# Methods\n\n`TeaBot` based on [`tg-yarl`](https://github.com/strikeentco/tg-yarl) (wrapper over Telegram Bot Api with additional features) package, it means `TeaBot` inherits all methods from [`tg-yarl`](https://github.com/strikeentco/tg-yarl).\n\n## Start methods\n\nDepending on what type of connection with Telegram is used (`webhook` or `long polling`), there are 2 methods to start the bot.\n\n### TeaBot.receive(message)\n\nTo work with `webhook`.\n\n#### Params\n* **message** (*Object*) - Message object received from Telegram using the webhook.\n\n### TeaBot.startPolling([options])\n\nTo work with `long polling`.\n\n#### Params\n* **[options]** (*Object*) - Polling options:\n  * **offset** (*Integer*) - Identifier of the first update to be returned (0 by default).\n  * **limit** (*Integer*) - Limits the number of updates to be retrieved (100 by default).\n  * **timeout** (*Integer*) - Timeout in seconds for long polling (60 by default).\n\n## Dialog object\n\n`Dialog object` stores bot current dialogue with the `user`, as well as commands ([full list here](https://github.com/strikeentco/teabot/tree/master/docs/#telegram-api)) for communication.\u003cbr\u003e\nIt can be obtained from the first parameter in `defineCommand` and `defineAction` callbacks, or directly from `TeaBot` object.\n\n### dialog.getAction()\n\nChecks whether the user is in a state of action, and if so `action name` will be returned, otherwise `false`.\n\n### dialog.startAction(action)\n\nStart the action. Then all processes occur in `defineAction` callbacks. Action callback will be called at the next incoming message.\n\n#### Params\n* **action** (*String*) - Name of the action defined in `defineAction`.\n\n### dialog.performAction(action)\n\nPerform the action. Then all processes occur in `defineAction` callbacks. Action callback will be called `immediately`.\n\n#### Params\n* **action** (*String*) - Name of the action defined in `defineAction`.\n\n### dialog.endAction([saveTemp])\n\nEnds the action and clears `dialog.tempData`.\n\n#### Params\n* **[saveTemp]** (*Boolean*) - If true, then `dialog.tempData` will not be cleared.\n\n#### More `dialog object` methods [in docs](https://github.com/strikeentco/teabot/tree/master/docs/#dialog-object).\n\n## Message object\n\n`Message object` stores processed incoming message, as well as its original copy.\u003cbr\u003e\nIt can be obtained from `dialog.message` or from the second parameter in `defineCommand` and `defineAction` callbacks.\n\n### message.getCommand()\n\nReturns `command` or empty string.\n\n### message.getArgument()\n\nIt returns the rest of the message, if it contains a `command` or the entire `message`.\n\n#### More `message object` methods [in docs](https://github.com/strikeentco/teabot/tree/master/docs/#message-object).\n\n## Commands\n\n`Commands` always starts with `/`.\n\n### TeaBot.defineCommand(command, callback)\n\n#### Params\n* **command** (*String|Array*) - Command or an array of commands. Also supports wildcards (Use `*` to match zero or more characters. A pattern starting with `!` will be negated).\n* **callback** (*Function*) - Callback which is invoked for this command/commands.\n\n### TeaBot.defineCommand(callback)\n\n#### Params\n* **callback** (*Function*) - Callback which is invoked if the given command is not defined or is not available.\n\n```js\nTeaBot\n  .defineCommand(['/start', '/help'], function (dialog, message) {\n    dialog.sendMessage('Hi there. This is a ' + message.getCommand() + ' command.');\n  })\n  .defineCommand('/hi*', function (dialog, message) { // wildcard\n    dialog.sendMessage('This command ' + message.getCommand() + ', starts with /hi');\n  })\n  .defineCommand(function (dialog) {\n    dialog.sendMessage('Send me /help for more information.');\n  });\n```\n\n## Actions\n\nYou can define some `actions` if you want to add interactivity to your bot. Or you want to split your code.\n\n### TeaBot.defineAction(action, callback)\n\n#### Params\n* **action** (*String|Array*) - Action or an array of actions. Also supports wildcards (Use `*` to match zero or more characters. A pattern starting with `!` will be negated).\n* **callback** (*Function*) - Callback which is invoked for this action/actions when it starts.\n\n```js\nTeaBot\n  .defineCommand('/help', function (dialog, message) {\n    if (message.getArgument()) {\n      dialog.performAction('/help:1'); // /help argument\n    } else {\n      dialog.startAction('/help:2').sendMessage('This is /help command.'); // /help\n    }\n  })\n  .defineCommand(function (dialog) {\n    dialog.sendMessage('Send me /help for more information.');\n  });\n\nTeaBot\n  .defineAction('/help:*', function (dialog) { // wildcard\n    dialog.endAction().sendMessage('This is ' + dialog.getAction() + ' action'); // if /help was with argument, then /help:1 action, otherwise /help:2\n  });\n```\n\n## Inline mode\n\n### TeaBot.inlineQuery(query, callback)\n\n#### Params\n* **query** (*String|Array*) - Query or an array of queries. Also supports wildcards (Use `*` to match zero or more characters. A pattern starting with `!` will be negated).\n* **callback** (*Function*) - Callback which is invoked for this query/queries.\n\n### TeaBot.inlineQuery(callback)\n\n#### Params\n* **callback** (*Function*) - Callback which is invoked if the given query is not defined, is not available or is empty.\n\n```js\nTeaBot\n  .inlineQuery('tay*', function (query) { // wildcard\n    query\n      .addGif(\n        { gif_url: 'https://33.media.tumblr.com/tumblr_m3xrtsmgs11rn435g.gif', thumb_url: 'https://33.media.tumblr.com/tumblr_m3xrtsmgs11rn435g.gif', gif_width: 500, gif_height: 247 }\n      )\n      .addGif(\n        { gif_url: 'http://blog.admissions.illinois.edu/wp-content/uploads/2015/08/Screaming-Taylor-Swift.gif', thumb_url: 'http://blog.admissions.illinois.edu/wp-content/uploads/2015/08/Screaming-Taylor-Swift.gif', gif_width: 480, gif_height: 267 }\n      )\n      .answer();\n  })\n  .inlineQuery(function (query) {\n    query\n      .addArticles([\n        { title: 'Test 1', message_text: 'test' },\n        { title: 'Test 2', message_text: 'test' },\n        { title: 'Test 3', message_text: 'test' }\n      ])\n      .answer();\n  });\n```\n\n#### More info about `inline mode` [in docs](https://github.com/strikeentco/teabot/tree/master/docs/#inline-mode).\n#### More info about `query object` [in docs](https://github.com/strikeentco/teabot/tree/master/docs/#query-object).\n\n## Plugins\n\nAt the moment `TeaBot` supports only `db` and `analytics` plugins, but in the future there will be more.\n\n### TeaBot.use(name, plugin)\n\n#### Params\n* **type** (*String*) - Plugin type: `db` or `analytics`.\n* **plugin** (*Object*) - Object with plugin.\n\n```js\nconst TeaBot = require('teabot')('TELEGRAM_BOT_TOKEN', 'TELEGRAM_BOT_NAME');\n\nTeaBot.use('analytics', require('teabot-botan')('BOTAN_TOKEN'));\n\nTeaBot.defineCommand(function (dialog, message) {\n  dialog.sendMessage('Echo: ' + message.text); // all message events will be sent directly to botan.io\n});\n\nTeaBot.startPolling();\n```\n\n### Available plugins:\n* DB:\n  * Redis - [teabot-redis](https://github.com/strikeentco/teabot-redis)\n  * Aerospike - [teabot-aerospike](https://github.com/strikeentco/teabot-aerospike)\n* Analytics:\n  * Botan - [teabot-botan](https://github.com/strikeentco/teabot-botan)\n\n#### More info about `plugins` [in docs](https://github.com/strikeentco/teabot/tree/master/docs/#teabotplugins).\n#### Information about how to write your own plugin [here](https://github.com/strikeentco/teabot/tree/master/docs/PLUGINS.md).\n\n## Errors\n\nBy default, no errors are displayed, except for those that may interfere start the bot. But with these methods you be able to handle errors by yourself.\n\n### TeaBot.error(error)\n\nUse this method in `Promise`, `Callback` functions and whenever you want.\n\n#### Params\n* **error** (*Object*) - Error object.\n\n### TeaBot.onError(callback)\n\nWhen error occurs or when `TeaBot.error()` is used, callback will be invoked.\n\n#### Params\n* **callback** (*Function*) - Callback which is invoked when `TeaBot.error()` is called (including internal call).\n\n```js\nTeaBot.onError(function (e) {\n  console.error('TeaBot error:', e.stack);\n});\n\nTeaBot.defineCommand(function (dialog, message) {\n  dialog.sendMessage('Echo: ' + message.text).then(function () {\n    throw new Error('Test error 1');\n  }).catch(TeaBot.error);\n  throw new Error('Test error 2');\n});\n```\n\n# [Documentation](https://github.com/strikeentco/teabot/tree/master/docs/)\n\n# Examples\n* [@WezaBot](https://telegram.me/WezaBot) - [strikeentco/WezaBot](https://github.com/strikeentco/WezaBot) - weather bot written with TeaBot.\n\nOther examples [here](https://github.com/strikeentco/teabot/tree/master/examples/).\n\n# License\n\nThe MIT License (MIT)\u003cbr/\u003e\nCopyright (c) 2015-2016 Alexey Bystrov\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrikeentco%2Fteabot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrikeentco%2Fteabot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrikeentco%2Fteabot/lists"}