telegramds
v1.2.7
Published
Fast and efficient way of storing data to telegram with multiple capabilities
Downloads
41
Maintainers
Readme
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
- [x] Cached Data - retrieve data faster, data in the cache is still encrypted.
- [x] Data Encryption - you don't have to worry about ur files being decrypted.
- [x] 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 Types|Return Type| Type |
|--|--|--|
|ds.set(id<string>, data<any>)
**| boolean
| async
|ds.get(id<string>)
| any
|async
|ds.del(id<string>)
| boolean
|async
|ds.exist(id<string>)
| boolean
|non-async
|ds.getAll()
| object | async
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