All Projects → ubotindonesia → duagram

ubotindonesia / duagram

Licence: other
Telegram Framework for userbot and bot api, using nodejs.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to duagram

Telegram-UserBot
Abandoned.. Moved to https://github.com/TeamDerUntergang/Telegram-SedenUserBot
Stars: ✭ 38 (+58.33%)
Mutual labels:  mtproto, userbot
WTelegramClient
Telegram client API library written 100% in C# and .NET Standard
Stars: ✭ 192 (+700%)
Mutual labels:  mtproto, userbot
DevelopersUserbot
Telegram Userbot Made for Developers by Developers
Stars: ✭ 25 (+4.17%)
Mutual labels:  userbot
tdlight-java
Complete Bot and Userbot Telegram library based on TDLib
Stars: ✭ 128 (+433.33%)
Mutual labels:  mtproto
aiotdlib
Python asyncio Telegram client based on TDLib https://github.com/tdlib/td
Stars: ✭ 63 (+162.5%)
Mutual labels:  mtproto
AsenaUserBot
Asena UserBot is the most advantageous and fast UserBot with changeable language and permanent plugin system.
Stars: ✭ 133 (+454.17%)
Mutual labels:  userbot
python-tdlib
full oop python 3 tdlib wrapper, fast, thread safe
Stars: ✭ 20 (-16.67%)
Mutual labels:  mtproto
Mtproto Core
Telegram API JS (MTProto) client library for browser and nodejs
Stars: ✭ 242 (+908.33%)
Mutual labels:  mtproto
tgEasy
tgEasy | Easy for a Brighter Shine | Monkey Patcher Addon for Pyrogram
Stars: ✭ 36 (+50%)
Mutual labels:  mtproto
tgcalls
Voice chats, private incoming and outgoing calls in Telegram for Developers
Stars: ✭ 408 (+1600%)
Mutual labels:  mtproto
nimgram
An MTProto client written in Nim 👑
Stars: ✭ 61 (+154.17%)
Mutual labels:  mtproto
TelegramCommunicationJS
A pure script to communicate with Telegram server without any Third-party tools and library.
Stars: ✭ 21 (-12.5%)
Mutual labels:  mtproto
One4uBot
Telegram Userbot Project to helping your Telegram experience based on PaperplaneExtended - Our Support https://t.me/userbotindo,
Stars: ✭ 51 (+112.5%)
Mutual labels:  userbot
USERGE-X
USERGE-X. What the X ?
Stars: ✭ 133 (+454.17%)
Mutual labels:  userbot
mtproto-js
🚀 Fastest ever MTProto JavaScript implementation
Stars: ✭ 23 (-4.17%)
Mutual labels:  mtproto
vpns
A collection of vpns
Stars: ✭ 112 (+366.67%)
Mutual labels:  mtproto
Jsmtproxy
High Performance NodeJS MTProto Proxy
Stars: ✭ 254 (+958.33%)
Mutual labels:  mtproto
WhatsGram
WhatsApp userbot with Telegram bot integration.
Stars: ✭ 85 (+254.17%)
Mutual labels:  userbot
Nana-Bot
Telegram Modular Userbot using python3.7
Stars: ✭ 38 (+58.33%)
Mutual labels:  userbot
LyricsPyRobot
A Telegram bot for searching lyrics.
Stars: ✭ 29 (+20.83%)
Mutual labels:  mtproto

duaGram

Telegram Framework for userbot and or bot api, using nodejs.

GitHub last commit GitHub release (latest by date) npm node-current GitHub code size in bytes GitHub repo size Lines of code GitHub top language GitHub all releases GitHub Discussions npm GitHub pull requests GitHub issues

duagram

GitHub watchers GitHub forks GitHub Repo stars

WARNING!

Use at Your Own Risk.

I don't take any responsibility from actions made by you or on your account.

History

Support

  • Issues
  • Contributor are welcome...

Install

npm i duagram

or

yarn add duagram

or

pnpm add duagram

Quick Start

const { duaGram } = require("duagram");

const bot = new duaGram({
    api_id: 1,
    api_hash: 'your-api-hash',
    // Fill in the session here if you have one, or leave it blank
    session: '', 
});

bot.cmd('ping', (ctx) => {
    console.log(ctx);
    // bot.sendMessage(ctx, 'pong'); // or:
    // bot.sendMessage(ctx.chat.id, 'pong'); // or:
    return ctx.reply('pong!');    
});

bot.start();

API TELEGRAM

To use the duaGram, you first have to get API ID dan API HASH.

Get it from https://my.telegram.org

Token Bot

If you connect use Bot API, get a bot account by chatting with BotFather.

BotFather will give you a token, something like 123456789:AbCdfGhIJKlmNoQQRsTUVwxyZ.

More Example

Do you need more example? Check this page.

User Login

source example
const { duaGram, terminal } = require("duagram");

const bot = new duaGram({
    api_id: 1,
    api_hash: 'your-api-hash',

    logLevel: 1, // 0 false, 1 event, 2 detail
    logDetail: "none", // none, error, warn, info, debug

    // Fill in the session here if you have one, or leave it blank
    session: '', 

    // 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:
    floodSleepThreshold: 120, 

    // Mark message history as read
    markRead: false 
});

bot.on('message', (ctx, _ctx) => {
    terminal.debug('Ctx Duagram');
    console.log(ctx);
});

bot.cmd('ping', (ctx) => {
    bot.sendMessage(ctx, 'Pong!', { replyToMsgId: ctx.id });
});

bot.cmd('upload', async (ctx) => {
    terminal.info('Starting upload...');
    let file = './photo.jpg';
    return bot.sendFile(ctx.chat.id, file);

});

bot.cmd('version', (ctx) => {
    return bot.sendMessage(ctx, `<code>${JSON.stringify(bot.version, null, 2)}<code>`, { parse_mode: 'HTML' });
});

bot.start();

Bot Login

Login with Bot API Token

source example
const { duaGram, terminal, Helper } = require("duagram");

const bot = new duaGram({
    api_id: 1,
    api_hash: 'your-api-hash',
    as_bot_api: true,
    bot_token: 'your-token-bot'
});

// event all new message
bot.on('message', async (ctx) => {
    terminal.debug('Ctx Duagram');
    console.log(ctx);
});

bot.cmd('ping', (ctx) => {
    return ctx.reply('Pong!', { replyToMsgId: ctx.id });
});

bot.cmd('upload', async (ctx) => {
    terminal.info('Starting upload...');
    let file = './photo.jpg';
    return await bot.sendFile(ctx.chat.id, file);

});

// bot API
bot.cmd('start', async (ctx) => {
    // message in only
    if (ctx.out) return false;

    if (!bot.asBotApi) {
        return bot.sendMessage(ctx, "I'm not bot api 😅")
    }

    let chat_id = ctx.chat.id;
    if (ctx.chat.type == 'channel') {
        chat_id = bot.Helper.chat.to_api(chat_id);
    }

    // if Bot API, send with Bot API can too
    let reply_markup = JSON.stringify({
        inline_keyboard: [
            [
                bot.Helper.Button.url('👥 uBotIndonesia', 'https://t.me/ubotindonesia')
            ], [
                bot.Helper.Button.text('One', 'cb1'),
                bot.Helper.Button.text('Two', 'cb2')
            ]
        ]
    });

    let more = {
        parse_mode: 'html',
        reply_markup
    }

    return bot.BotApi.sendMessage(chat_id, 'This message from <b>Bot Api</b>', more)
        .then(result => {
            terminal.log('Result: BotApi sendMessage')
            console.log(result);
        })
        .catch(error => terminal.error(error.message));
});

bot.cmd('version', (ctx) => {
    return bot.sendMessage(ctx, `<code>${JSON.stringify(bot.version, null, 2)}<code>`, { parse_mode: 'HTML' });
});

bot.start();

Documentation

duaGram

Session

Options

const bot = new duaGram(options);

Item Description Default
api_id get it from https://my.telegram.org
api_hash get it from https://my.telegram.org
session session string
session_name Session name -
local with local database false
logLevel Show log level 0 off, 1 event name, 2 detail 1
logDetail Event Detail (none, error, warn, info, debug) info
as_bot_api Login as bot API? 0 false / 1 true 0
bot_token Token Bot API @botfahter
connectionRetries Connection Retry 3
floodSleepThreshold FloodWait error ? Set this 120
markRead Mark message history as read TRUE
cmdPrefix prefix for command trigger !/.

Event

Available :

  • on(updateType, stop=true)
  • cmd(string, callback, stop=true)
  • hear(regex|string, callback, stop=true)
  • hears(regex|string, callback, stop=true) alias hear
  • command alias cmd

Example:

bot.cmd('ping', callback);
bot.hear('hello', callback);
bot.hear(/^!time$/i, callback);

bot.hear(/coffee/i, callback, false); // if found stopable? false. So, catch condition anatoher again bellow
bot.hear(/tea/i, callback);

Update Type

Example:

bot.on('message', (ctx, _ctx) => terminal.less(ctx) );

Available:

  • connected
  • raw
  • message
  • media
  • all class names in mtproto, according to the log details

You can see on ctx.event message too.

Class name event example:

  • UpdateNewMessage
  • UpdateShortMessage
  • UpdateReadHistoryOutbox
  • UpdateDeleteMessages
  • UpdateUserTyping
  • etc... schema

Result object raw without middleware effect.

Properties

Method or Accessors of duaGram.

method description
telegram collection function duagram
Api access for API Telegram
client client connecton
BotApi wrapper for Bot Api Telegram
terminal console replacement for colorful and bettermore
lessLog better thanconsole.log function, less prefix _ field
asBotApi true/false
version duagrams version info
cmdPrefix default is.!/
Helper Go to helper doc

Example:

const bot = new duaGram({...});

bot.cmdPrefix = '~'; // bot.cmd('ping', ..) => ~ping
console.log(bot.version);

Alias

  • tg (alias telegram)
  • invoke(params)
  • sendMessage(peer, text, more)
  • ... etc (like telegram method)

Telegram

method

  • invoke(params)
  • getPeerId(ctx)
  • sendMessage(peer, text, more)
  • editMessage(peer, id, text, more)
  • deleteMessages(peer, ids, more)
  • forwardMessages(peerFrom, peerTo, ids, more)
  • getMessages(peer, ids)
  • pinMessage(peer, id, more)
  • unpinAllMessages(peer)
  • readHistory(peer, more)
  • getUserPhotos(peer, more)
  • getUserInfo(peer)
  • editAdmin(peerChatId, peerUserId, more = {})
  • editBanned(peerChatId, peerUserId, more = {})
  • joinGroup(peer)
  • readMentions(peer)
  • readMessageContents(id)
  • deleteHistory(peer, more)
  • deleteUserHistory(channelId, userId)

Middleware

Middleware 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.

You can imagine middleware as a chain of logic connection your bot to the Telegram request.

Middleware 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.

bot.middleware((ctx, next) => {
    ctx.additional = 'message test from middleware';
    next();
});

bot.cmd('plus', async (ctx) => {   
    if (!ctx.out)
        return bot.sendMessage(ctx.chat.id, `Hooked: ${ctx.additional}`);
})

Middleware List

Middleware more information: click here.

client

Client Details

Method

  • start()
  • checkAuthorization()
  • signInUser()
  • signInUserWithQrCode()
  • signInWithPassword()
  • inlineQuery()
  • buildReplyMarkup()
  • downloadFile()
  • downloadProfilePhoto()
  • downloadMedia()
  • setParseMode()
  • iterMessages()
  • getMessages()
  • sendMessage()
  • forwardMessages()
  • editMessage()
  • iterDialogs()
  • getDialogs()
  • iterParticipants()
  • getParticipants()
  • removeEventHandler()
  • listEventHandlers()
  • uploadFile()
  • sendFile()
  • invoke()
  • getMe()
  • isBot()
  • isUserAuthorized()
  • getInputEntity()
  • getPeerId()
  • connect()
  • getDC()
  • disconnect()
  • destroy()
  • ... etc

Reference

List details

Last Words

Happy nge-bot!

If you are Indonesian, let's join the @ubotindonesia telegram group.

see you again ^^

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].