1.2.7 • Published 12 months ago

telegramds v1.2.7

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

TelegramDS

This package allows you to use telegram's API to store, retrieve and delete data securely between you and the bot or a group

Install: npm i telegramds

Encryption Method: AES-CBC-256

  • Cached Data - retrieve data faster, data in the cache is still encrypted.
  • Data Encryption - you don't have to worry about ur files being decrypted.
  • Store Objects, Images and Videos

Initialization

Firstly, Create a Telegram Bot

const telegramds = require("telegramds");
const telegramBotToken = "xxxxxx:xxxxxxxxxxxxxx"; // create a bot on telegram and replace the varbiable with ur bot token
const customPassphrase = "ANYTHING, BUT MUST BE SECURE"; // should not be any longer than 64 characters

const config = telegramds.genconfig(customPassphrase, telegramBotToken); // ur config will be outputted to the console in json
console.log(config); // copy the config for future uses

telegramds.run(JSON.parse(config), __dirname);

#1: After running this script, text your bot on telegram /chatid

#2: It should respond with a positive or sometimes negative number.

#3: Copy this number and put it as the "chatid" field in ur config.

#4: Store your config in a JSON file and require it whenever using, Example:

const telegramds = require("telegramds");
const config = require("PATH_TO_JSON_FILE");
telegramds.run(config, __dirname, function(){
    console.log("TelegramDS bot online!");
});

// Access the Datastore
const ds = telegramds.ds; // Scroll down to see functions

// Access the BOT
const bot = telegramds.bot;
// bot.on(text<string/regex>, (...) => {});
// bot.onText(text<regex/regex>, (msg<{}>, match<{}>) => {});
// bot.sendMessage(chatid<number/string>, <string>);
// documentation: https://www.npmjs.com/package/node-telegram-bot-api

Functions

Functions Usage with TypesReturn TypeType
ds.set(id<string>, data<any>)**booleanasync
ds.get(id<string>)anyasync
ds.del(id<string>)booleanasync
ds.exist(id<string>)booleannon-async
ds.getAll()objectasync
const fs = require("fs");
const bot = telegramds.bot;
const ds = telegramds.ds;
const config = require("PATH_TO_JSON_FILE")
telegramds.run(config, __dirname, function(){
    console.log("TelegramDS bot online!");
}); // only run this 1 time

async function main() {   
 // Strings/Numbers
 await ds.set("test","hello");
 console.log(await ds.get("test")); // "hello"
 await ds.del("test"); // delete the data
 console.log(await ds.get("test")); // undefined
 
 // Objects
 await ds.set("eatit", {hi: true});
 console.log(await ds.get("eatit")); // {hi: true}
 await ds.del("eatit"); // delete the data
 console.log(await ds.get("eatit")); // undefined
 
 // Files
 let file = fs.readFileSync("./path/to/image.png"); // read the file
 // typeof(file) == "object";
 await ds.set("file", file.toString("hex"));
 console.log(Buffer.from(await ds.get("file"), "hex")); // <Buffer>
 
 /* Others */
 // Retrieve all data with their values [ could be slow if data is big ]
 let allData = ds.getAll();
 console.log(allData) // -> { "file": <Buffer> }
 
 // Checks if the data id/key exist without getting the actual data
 // Useful for when you want to check an id without waiting for the data
 let exist = ds.exist("example"); // <boolean>
 consol.log(exist);
}
main(); // Run the function
1.2.0

12 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.9

12 months ago

1.2.7

12 months ago

1.1.8

12 months ago

1.0.9

1 year ago

1.2.6

12 months ago

1.1.7

12 months ago

1.0.8

1 year ago

1.2.5

12 months ago

1.1.6

12 months ago

1.0.7

1 year ago

1.2.4

12 months ago

1.1.5

1 year ago

1.2.3

12 months ago

1.1.4

1 year ago

1.2.2

12 months ago

1.2.1

12 months ago

1.1.2

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago