{"id":13793922,"url":"https://github.com/ubotindonesia/duagram","last_synced_at":"2025-05-12T20:31:16.952Z","repository":{"id":45058304,"uuid":"384636221","full_name":"ubotindonesia/duagram","owner":"ubotindonesia","description":"Telegram Framework for userbot and bot api, using nodejs.","archived":false,"fork":false,"pushed_at":"2022-01-12T02:48:47.000Z","size":876,"stargazers_count":27,"open_issues_count":1,"forks_count":8,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-02T21:02:43.969Z","etag":null,"topics":["mtproto","nodejs","telegram","userbot"],"latest_commit_sha":null,"homepage":"https://t.me/duagram","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ubotindonesia.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-10T07:17:06.000Z","updated_at":"2024-08-15T12:19:33.000Z","dependencies_parsed_at":"2022-09-02T22:11:12.979Z","dependency_job_id":null,"html_url":"https://github.com/ubotindonesia/duagram","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubotindonesia%2Fduagram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubotindonesia%2Fduagram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubotindonesia%2Fduagram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ubotindonesia%2Fduagram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ubotindonesia","download_url":"https://codeload.github.com/ubotindonesia/duagram/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253816733,"owners_count":21968875,"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":["mtproto","nodejs","telegram","userbot"],"created_at":"2024-08-03T23:00:33.380Z","updated_at":"2025-05-12T20:31:16.106Z","avatar_url":"https://github.com/ubotindonesia.png","language":"JavaScript","funding_links":[],"categories":["Library \u0026 Framework"],"sub_categories":["Tutorial Made"],"readme":"## duaGram\n\nTelegram Framework for userbot and or bot api, using nodejs.\n\n![GitHub last commit](https://img.shields.io/github/last-commit/ubotindonesia/duagram) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ubotindonesia/duagram) ![npm](https://img.shields.io/npm/v/duagram) ![node-current](https://img.shields.io/node/v/duagram?color=red) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ubotindonesia/duagram?color=fef) ![GitHub repo size](https://img.shields.io/github/repo-size/ubotindonesia/duagram?color=fee) ![Lines of code](https://img.shields.io/tokei/lines/github/ubotindonesia/duagram?color=dee) ![GitHub top language](https://img.shields.io/github/languages/top/ubotindonesia/duagram?color=dee)  ![GitHub all releases](https://img.shields.io/github/downloads/ubotindonesia/duagram/total) ![GitHub Discussions](https://img.shields.io/github/discussions/ubotindonesia/duagram) ![npm](https://img.shields.io/npm/dt/duagram?color=blue) ![GitHub pull requests](https://img.shields.io/github/issues-pr/ubotindonesia/duagram) ![GitHub issues](https://img.shields.io/github/issues/ubotindonesia/duagram) \n\n\n![duagram](https://github.com/ubotindonesia/duagram/raw/main/asset/2gram%20banner%20small.jpg)\n\n\n![GitHub watchers](https://img.shields.io/github/watchers/ubotindonesia/duagram?style=social) ![GitHub forks](https://img.shields.io/github/forks/ubotindonesia/duagram?style=social)\n![GitHub Repo stars](https://img.shields.io/github/stars/ubotindonesia/duagram?style=social) \n\n### WARNING!\n\nUse at Your Own Risk.\n\n\u003e I don't take any responsibility from actions made by you or on your account.\n\n### History\n\n- [Release](https://github.com/ubotindonesia/duagram/releases)\n\n### Support\n\n- [Issues](https://github.com/ubotindonesia/duagram/issues)\n- Contributor are welcome...\n\n## Install\n\n`npm i duagram`\n\nor\n\n`yarn add duagram`\n\nor\n\n`pnpm add duagram`\n\n## Quick Start\n\n```javascript\nconst { duaGram } = require(\"duagram\");\n\nconst bot = new duaGram({\n    api_id: 1,\n    api_hash: 'your-api-hash',\n    // Fill in the session here if you have one, or leave it blank\n    session: '', \n});\n\nbot.cmd('ping', (ctx) =\u003e {\n    console.log(ctx);\n    // bot.sendMessage(ctx, 'pong'); // or:\n    // bot.sendMessage(ctx.chat.id, 'pong'); // or:\n    return ctx.reply('pong!');    \n});\n\nbot.start();\n```\n\n## API TELEGRAM\n\nTo use the duaGram, you first have to get API ID dan API HASH.\n\nGet it from [https://my.telegram.org](https://my.telegram.org)\n\n\n### Token Bot\n\nIf you connect use Bot API, get a bot account by chatting with [BotFather](https://core.telegram.org/bots#6-botfather).\n\nBotFather will give you a token, something like `123456789:AbCdfGhIJKlmNoQQRsTUVwxyZ`.\n\n\n## More Example\n\n\u003e Do you need more example? [Check this page](https://github.com/ubotindonesia/duagram/tree/main/examples).\n\n### User Login\n\n\u003cdetails\u003e\u003csummary\u003esource example\u003c/summary\u003e\n\n```javascript\nconst { duaGram, terminal } = require(\"duagram\");\n\nconst bot = new duaGram({\n    api_id: 1,\n    api_hash: 'your-api-hash',\n\n    logLevel: 1, // 0 false, 1 event, 2 detail\n    logDetail: \"none\", // none, error, warn, info, debug\n\n    // Fill in the session here if you have one, or leave it blank\n    session: '', \n\n    // The most common error is the FloodWait error which is caused by calling a method multiple times in a short period and acts as a spam filter from telegram. So:\n    floodSleepThreshold: 120, \n\n    // Mark message history as read\n    markRead: false \n});\n\nbot.on('message', (ctx, _ctx) =\u003e {\n    terminal.debug('Ctx Duagram');\n    console.log(ctx);\n});\n\nbot.cmd('ping', (ctx) =\u003e {\n    bot.sendMessage(ctx, 'Pong!', { replyToMsgId: ctx.id });\n});\n\nbot.cmd('upload', async (ctx) =\u003e {\n    terminal.info('Starting upload...');\n    let file = './photo.jpg';\n    return bot.sendFile(ctx.chat.id, file);\n\n});\n\nbot.cmd('version', (ctx) =\u003e {\n    return bot.sendMessage(ctx, `\u003ccode\u003e${JSON.stringify(bot.version, null, 2)}\u003ccode\u003e`, { parse_mode: 'HTML' });\n});\n\nbot.start();\n```\n\n\u003c/details\u003e\n\n### Bot Login\n\nLogin with Bot API Token\n\n\u003cdetails\u003e\u003csummary\u003esource example\u003c/summary\u003e\n\n```javascript\nconst { duaGram, terminal, Helper } = require(\"duagram\");\n\nconst bot = new duaGram({\n    api_id: 1,\n    api_hash: 'your-api-hash',\n    as_bot_api: true,\n    bot_token: 'your-token-bot'\n});\n\n// event all new message\nbot.on('message', async (ctx) =\u003e {\n    terminal.debug('Ctx Duagram');\n    console.log(ctx);\n});\n\nbot.cmd('ping', (ctx) =\u003e {\n    return ctx.reply('Pong!', { replyToMsgId: ctx.id });\n});\n\nbot.cmd('upload', async (ctx) =\u003e {\n    terminal.info('Starting upload...');\n    let file = './photo.jpg';\n    return await bot.sendFile(ctx.chat.id, file);\n\n});\n\n// bot API\nbot.cmd('start', async (ctx) =\u003e {\n    // message in only\n    if (ctx.out) return false;\n\n    if (!bot.asBotApi) {\n        return bot.sendMessage(ctx, \"I'm not bot api 😅\")\n    }\n\n    let chat_id = ctx.chat.id;\n    if (ctx.chat.type == 'channel') {\n        chat_id = bot.Helper.chat.to_api(chat_id);\n    }\n\n    // if Bot API, send with Bot API can too\n    let reply_markup = JSON.stringify({\n        inline_keyboard: [\n            [\n                bot.Helper.Button.url('👥 uBotIndonesia', 'https://t.me/ubotindonesia')\n            ], [\n                bot.Helper.Button.text('One', 'cb1'),\n                bot.Helper.Button.text('Two', 'cb2')\n            ]\n        ]\n    });\n\n    let more = {\n        parse_mode: 'html',\n        reply_markup\n    }\n\n    return bot.BotApi.sendMessage(chat_id, 'This message from \u003cb\u003eBot Api\u003c/b\u003e', more)\n        .then(result =\u003e {\n            terminal.log('Result: BotApi sendMessage')\n            console.log(result);\n        })\n        .catch(error =\u003e terminal.error(error.message));\n});\n\nbot.cmd('version', (ctx) =\u003e {\n    return bot.sendMessage(ctx, `\u003ccode\u003e${JSON.stringify(bot.version, null, 2)}\u003ccode\u003e`, { parse_mode: 'HTML' });\n});\n\nbot.start();\n```\n\n\u003c/details\u003e\n\n## Documentation\n\n## duaGram\n\n### Session\n\n- Generator: [https://telegram.banghasan.com/ubotstring/](https://telegram.banghasan.com/ubotstring/)\n\n### Options\n\n`const bot = new duaGram(options);`\n\n\n| **Item**            | **Description**                                                | **Default** |\n| --------------------- | ---------------------------------------------------------------- | ------------- |\n| api\\_id             | get it from [https://my.telegram.org](https://my.telegram.org/) |             |\n| api\\_hash           | get it from [https://my.telegram.org](https://my.telegram.org/) |             |\n| session             | session string                                                 |             |\n| session_name | Session name | - |\n| local | with local database | `false` |\n| logLevel            | Show log level 0 off, 1 event name, 2 detail                   | 1           |\n| logDetail           | Event Detail (none, error, warn, info, debug)                  | info        |\n| as\\_bot\\_api        | Login as bot API? 0 false / 1 true                             | 0           |\n| bot\\_token          | Token Bot API [@botfahter](https://t.me/botfather)             |             |\n| connectionRetries   | Connection Retry                                               | 3           |\n| floodSleepThreshold | FloodWait error ? Set this                                     | `120`         |\n| markRead            | Mark message history as read                                   | `TRUE`        |\n| cmdPrefix           | prefix for command trigger                                     | `!/.`\n\n### Event\n\nAvailable :\n\n- **on**(`updateType, stop=true`)\n- **cmd**(`string, callback, stop=true`)\n- **hear**(`regex|string, callback, stop=true`)\n- hears(`regex|string, callback, stop=true`) alias hear\n- **command** alias `cmd`\n\nExample:\n\n```javascript\nbot.cmd('ping', callback);\nbot.hear('hello', callback);\nbot.hear(/^!time$/i, callback);\n\nbot.hear(/coffee/i, callback, false); // if found stopable? false. So, catch condition anatoher again bellow\nbot.hear(/tea/i, callback);\n```\n\n### Update Type\n\nExample:\n\n```javascript\nbot.on('message', (ctx, _ctx) =\u003e terminal.less(ctx) );\n```\n\nAvailable:\n\n- connected\n- raw\n- message\n- media\n- all class names in mtproto, according to the log details\n\n\u003e You can see on `ctx.event` message too.\n\nClass name event example:\n\n- UpdateNewMessage\n- UpdateShortMessage\n- UpdateReadHistoryOutbox\n- UpdateDeleteMessages\n- UpdateUserTyping\n- etc... [schema](https://core.telegram.org/schema)\n\nResult `object` **raw** without middleware effect.\n\n### Properties\n\nMethod or Accessors of duaGram.\n\n\n| method    | description                                                       |\n| ----------- | ------------------------------------------------------------------- |\n| telegram  | collection function duagram                                       |\n| Api       | access for [API Telegram](https://core.telegram.org/)              |\n| client    | client connecton                                                  |\n| BotApi    | wrapper for [Bot Api Telegram](https://core.telegram.org/bots/api) |\n| terminal  | console replacement for colorful and bettermore                   |\n| lessLog   | better than`console.log` function, less prefix \\_ field           |\n| asBotApi  | `true`/`false`                                                    |\n| version   | duagrams version info                                             |\n| cmdPrefix | default is`.!/`                                                   |\n| Helper    | [Go to helper doc](https://github.com/ubotindonesia/duagram/blob/main/docs/helper.md)                                                          |\n\nExample:\n\n```javascript\nconst bot = new duaGram({...});\n\nbot.cmdPrefix = '~'; // bot.cmd('ping', ..) =\u003e ~ping\nconsole.log(bot.version);\n\n```\n\n#### Alias\n\n- tg (alias `telegram`)\n- invoke(`params`)\n- sendMessage(`peer, text, more`)\n- ... etc (like **telegram** method)\n\n## Telegram\n\n### method\n\n- invoke(`params`)\n- getPeerId(`ctx`)\n- sendMessage(`peer, text, more`)\n- editMessage(`peer, id, text, more`)\n- deleteMessages(`peer, ids, more`)\n- forwardMessages(`peerFrom, peerTo, ids, more`)\n- getMessages(`peer, ids`)\n- pinMessage(`peer, id, more`) \n- unpinAllMessages(`peer`)\n- readHistory(`peer, more`)\n- getUserPhotos(`peer, more`)\n- getUserInfo(`peer`)\n- editAdmin(`peerChatId, peerUserId, more = {}`)\n- editBanned(`peerChatId, peerUserId, more = {}`)\n- joinGroup(`peer`)\n- readMentions(`peer`)\n- readMessageContents(`id`)\n- deleteHistory(`peer, more`)\n- deleteUserHistory(`channelId, userId`)\n\n## Middleware\n\nMiddleware is an essential part of any modern framework. It allows you to modify requests and responses as they pass between the Telegram and your bot.\n\nYou can imagine middleware as a chain of logic connection your bot to the Telegram request.\n\nMiddleware normally takes two parameters `(ctx, next)`, `ctx` is the context for one Telegram update, `next` is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.\n\n```javascript\nbot.middleware((ctx, next) =\u003e {\n    ctx.additional = 'message test from middleware';\n    next();\n});\n\nbot.cmd('plus', async (ctx) =\u003e {   \n    if (!ctx.out)\n        return bot.sendMessage(ctx.chat.id, `Hooked: ${ctx.additional}`);\n})\n```\n\n### Middleware List\n\n- [duaGram rate-limit](https://www.npmjs.com/package/duagram-ratelimit)\n\nMiddleware more information: [click here](https://github.com/ubotindonesia/duagram/blob/main/docs/middleware.md).\n\n## client\n\n\u003cdetails\u003e\u003csummary\u003eClient Details\u003c/summary\u003e\n\n### Method\n\n- start()\n- checkAuthorization()\n- signInUser()\n- signInUserWithQrCode()\n- signInWithPassword()\n- inlineQuery()\n- buildReplyMarkup()\n- downloadFile()\n- downloadProfilePhoto()\n- downloadMedia()\n- setParseMode()\n- iterMessages()\n- getMessages()\n- sendMessage()\n- forwardMessages()\n- editMessage()\n- iterDialogs()\n- getDialogs()\n- iterParticipants()\n- getParticipants()\n- removeEventHandler()\n- listEventHandlers()\n- uploadFile()\n- sendFile()\n- invoke()\n- getMe()\n- isBot()\n- isUserAuthorized()\n- getInputEntity()\n- getPeerId()\n- connect()\n- getDC()\n- disconnect()\n- destroy()\n- ... etc\n\n\u003c/details\u003e\n\n## Reference\n\n\u003cdetails\u003e\u003csummary\u003eList details\u003c/summary\u003e\n\n- [API Telegram](https://core.telegram.org/)\n- [Schema](https://core.telegram.org/schema)\n- [Bot API Telegram](https://core.telegram.org/bots/api)\n- [GramJS](https://gram.js.org/)\n- [GramJS Beta](https://gram.js.org/beta/classes/client_telegramclient.telegramclient.html)\n- [GramJS Gitbook](https://painor.gitbook.io/gramjs/)\n- [Bot Api Example](https://core.telegram.org/bots/samples)\n- [NodeJS](https://nodejs.org/dist/latest/docs/api/)\n- [MDN Mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript)\n- [VS Codium](https://vscodium.com/)\n\n\u003c/details\u003e\n\n## Last Words\n\n### Happy nge-bot!\n\nIf you are Indonesian, let's join the [@ubotindonesia](https://t.me/ubotindonesia) telegram group.\n\n_see you again_ ^^\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fubotindonesia%2Fduagram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fubotindonesia%2Fduagram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fubotindonesia%2Fduagram/lists"}