How to use telegram - 10 common examples

To help you get started, we’ve selected a few telegram examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pmarrapese / tg-logsaver / lib / TelegramClient.js View on Github external
return new Promise((resolve, reject) => {
      let app = {
        id: this.appId,
        hash: this.hash,
        version: this.version,
        langCode: DEFAULT_LANGUAGE_CODE,
        deviceModel: '(n/a)',
        systemVersion: '(n/a)',
        authKey: this.authKey
      };

      this.client = tg.createClient(app, this.dataCenter, (e) => {
        if (e) {
          return reject(e);
        }

        if (this.client.isReady()) {
          // Nothing else to do.
          return resolve();
        }

        // Create MTProto auth key before resolving.
        this.client.createAuthKey((authKey) => {
          this.authKey = authKey;
          resolve();
        });
      });
    });
github the-AjK / btb / src / manager.js View on Github external
offset: req.query.offset || undefined,
            limit: req.query.limit || 100,
            sort: {
                updatedAt: -1
            }
        };
    if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
        //non root user limitations
        select.deleted = -1;
        select.loginCounter = -1;
        select.settings = -1;
        select.beerCounter = -1;
        select.lastLogin = -1;
        select.lastIp = -1;
        select["telegram.id"] = -1;
        select["telegram.enabled"] = 1;
        select["telegram.username"] = -1;
        select["telegram.first_name"] = -1;
        select["telegram.last_name"] = -1;
        select["telegram.language_code"] = -1;
        query.deleted = false;
    }
    if (!id) {
        DB.User.find(query, select, options, (err, users) => {
            if (err) {
                console.error(err);
                return res.sendStatus(500);
            }
            res.send(users);
        });
    } else {
        query._id = id;
github the-AjK / btb / src / manager.js View on Github external
DB.User.findOneAndUpdate(query, data, options, (err, user) => {
        if (err) {
            console.error(err);
            return res.sendStatus(500);
        } else if (!user) {
            return res.sendStatus(404);
        }
        if (!user.telegram.enabled && data.$set && data.$set["telegram.enabled"] == true && data.sendNotification) {
            botNotifications.accountEnabledDisabled(user, true);
            bot.broadcastMessage("User *" + user.email + "* enabled by *" + req.user.email + "*", accessLevels.admin, null, true);
        } else if (user.telegram.enabled && data.$set && data.$set["telegram.enabled"] == false && data.sendNotification) {
            botNotifications.accountEnabledDisabled(user, false);
            bot.broadcastMessage("User *" + user.email + "* disabled by *" + req.user.email + "*", accessLevels.admin, null, true);
        }
        res.sendStatus(200);
    });
github the-AjK / btb / src / manager.js View on Github external
sort: {
                updatedAt: -1
            }
        };
    if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
        //non root user limitations
        select.deleted = -1;
        select.loginCounter = -1;
        select.settings = -1;
        select.beerCounter = -1;
        select.lastLogin = -1;
        select.lastIp = -1;
        select["telegram.id"] = -1;
        select["telegram.enabled"] = 1;
        select["telegram.username"] = -1;
        select["telegram.first_name"] = -1;
        select["telegram.last_name"] = -1;
        select["telegram.language_code"] = -1;
        query.deleted = false;
    }
    if (!id) {
        DB.User.find(query, select, options, (err, users) => {
            if (err) {
                console.error(err);
                return res.sendStatus(500);
            }
            res.send(users);
        });
    } else {
        query._id = id;
        DB.User.findOne(query, select, (err, user) => {
            if (err) {
github the-AjK / btb / src / manager.js View on Github external
options = {
            offset: req.query.offset || undefined,
            limit: req.query.limit || 100,
            sort: {
                updatedAt: -1
            }
        };
    if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
        //non root user limitations
        select.deleted = -1;
        select.loginCounter = -1;
        select.settings = -1;
        select.beerCounter = -1;
        select.lastLogin = -1;
        select.lastIp = -1;
        select["telegram.id"] = -1;
        select["telegram.enabled"] = 1;
        select["telegram.username"] = -1;
        select["telegram.first_name"] = -1;
        select["telegram.last_name"] = -1;
        select["telegram.language_code"] = -1;
        query.deleted = false;
    }
    if (!id) {
        DB.User.find(query, select, options, (err, users) => {
            if (err) {
                console.error(err);
                return res.sendStatus(500);
            }
            res.send(users);
        });
    } else {
github the-AjK / btb / src / manager.js View on Github external
}
        };
    if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
        //non root user limitations
        select.deleted = -1;
        select.loginCounter = -1;
        select.settings = -1;
        select.beerCounter = -1;
        select.lastLogin = -1;
        select.lastIp = -1;
        select["telegram.id"] = -1;
        select["telegram.enabled"] = 1;
        select["telegram.username"] = -1;
        select["telegram.first_name"] = -1;
        select["telegram.last_name"] = -1;
        select["telegram.language_code"] = -1;
        query.deleted = false;
    }
    if (!id) {
        DB.User.find(query, select, options, (err, users) => {
            if (err) {
                console.error(err);
                return res.sendStatus(500);
            }
            res.send(users);
        });
    } else {
        query._id = id;
        DB.User.findOne(query, select, (err, user) => {
            if (err) {
                console.error(err);
                return res.sendStatus(500);
github the-AjK / btb / src / manager.js View on Github external
updatedAt: -1
            }
        };
    if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
        //non root user limitations
        select.deleted = -1;
        select.loginCounter = -1;
        select.settings = -1;
        select.beerCounter = -1;
        select.lastLogin = -1;
        select.lastIp = -1;
        select["telegram.id"] = -1;
        select["telegram.enabled"] = 1;
        select["telegram.username"] = -1;
        select["telegram.first_name"] = -1;
        select["telegram.last_name"] = -1;
        select["telegram.language_code"] = -1;
        query.deleted = false;
    }
    if (!id) {
        DB.User.find(query, select, options, (err, users) => {
            if (err) {
                console.error(err);
                return res.sendStatus(500);
            }
            res.send(users);
        });
    } else {
        query._id = id;
        DB.User.findOne(query, select, (err, user) => {
            if (err) {
                console.error(err);
github pmarrapese / tg-logsaver / lib / TelegramClient.js View on Github external
constructor(appId, hash, version, dataCenter, encryptedAuthKey) {
    this.appId = appId;
    this.hash = hash;
    this.version = version;

    if (dataCenter) {
      let dcPieces = dataCenter.split(':');
      this.dataCenter = {
        host: dcPieces[0],
        port: dcPieces.length > 1 ? dcPieces[1] : DEFAULT_DATACENTER_PORT
      };
    } else {
      this.dataCenter = tg.PROD_PRIMARY_DC;
    }

    if (encryptedAuthKey) {
      this.authKey = tg.retrieveAuthKey(new Buffer(encryptedAuthKey, 'hex'), hash);
    }
  }
github pmarrapese / tg-logsaver / lib / TelegramClient.js View on Github external
this.appId = appId;
    this.hash = hash;
    this.version = version;

    if (dataCenter) {
      let dcPieces = dataCenter.split(':');
      this.dataCenter = {
        host: dcPieces[0],
        port: dcPieces.length > 1 ? dcPieces[1] : DEFAULT_DATACENTER_PORT
      };
    } else {
      this.dataCenter = tg.PROD_PRIMARY_DC;
    }

    if (encryptedAuthKey) {
      this.authKey = tg.retrieveAuthKey(new Buffer(encryptedAuthKey, 'hex'), hash);
    }
  }
github the-AjK / btb / src / manager.js View on Github external
limit: req.query.limit || 100,
            sort: {
                updatedAt: -1
            }
        };
    if (!checkUserAccessLevel(req.user.role, accessLevels.root)) {
        //non root user limitations
        select.deleted = -1;
        select.loginCounter = -1;
        select.settings = -1;
        select.beerCounter = -1;
        select.lastLogin = -1;
        select.lastIp = -1;
        select["telegram.id"] = -1;
        select["telegram.enabled"] = 1;
        select["telegram.username"] = -1;
        select["telegram.first_name"] = -1;
        select["telegram.last_name"] = -1;
        select["telegram.language_code"] = -1;
        query.deleted = false;
    }
    if (!id) {
        DB.User.find(query, select, options, (err, users) => {
            if (err) {
                console.error(err);
                return res.sendStatus(500);
            }
            res.send(users);
        });
    } else {
        query._id = id;
        DB.User.findOne(query, select, (err, user) => {