Socket
Socket
Sign inDemoInstall

tgb

Package Overview
Dependencies
0
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.4 to 0.0.5

src/markup.js

2

package.json
{
"name": "tgb",
"version": "0.0.4",
"version": "0.0.5",
"description": "The best choice for your Telegram Bots",

@@ -5,0 +5,0 @@ "homepage": "https://666.io",

@@ -14,3 +14,7 @@ [![Codacy][cod_b]][cod_l]

```
> tgb-cli --polling TOKEN --echo -j
```
[Full Bot API 3.5][3]

@@ -21,5 +25,5 @@

* [File as Buffer](#refSendFileAsBuffer): +
* [ReqAbort](#refReqAbort): +
* [ReqPause](#refReqAbort): +
* [Abort/Pause](#refReqAbort): +
* [TgUpload](#refTgUpload): +
* [Markup](#refMarkup): +
* [CLI](#refCLI): +

@@ -73,3 +77,3 @@ * Entities: +

// > send: tg @gamebot /start x http://db.gg
// send: tg @gamebot /start x http://db.gg
// https://core.telegram.org/bots/api#messageentity

@@ -171,2 +175,34 @@ ```

<a name="refMarkup"></a>
#### Markup
```js
const bot = tgb(process.env.TELEGRAM_BOT_TOKEN);
const {markup} = tgb;
// Set
bot.sendMessage(markup({
"chat_id": "0",
"text": "Hi"
}).keyboard(`A a| B b |C c\n X `));
// Remove
bot.sendMessage(markup({
"chat_id": "0",
"text": "Hi"
}).keyboard()); // .removeKeyboard()
// Reply
bot.sendMessage(markup({
"chat_id": "0",
"text": "Hi"
}).reply()); // .forceReply()
// keyboard(kb, oneTime[, resize = true, selective = false])
// removeKeyboard([selective = false])
// forceReply([selective = false])
```
<a name="refCLI"></a>

@@ -186,2 +222,5 @@ #### CLI

> tgb-cli --method sendMessage --d.chat_id 1 --data "{\"chat_id\":0,\"text\":\"Hi yo\"}"
> tgb-cli --download TOKEN --name x --id "AgADAgAD36gxGwWj2EuIQ9vvX_3kbh-cmg4ABDhqGLqV07c_phkBAAEC"
> tgb-cli --download --dir "./temp/" --id "AgADAgAD36gxGwWj2EuIQ9vvX_3kbh-cmg4ABDhqGLqV07c_phkBAAEC"
```

@@ -247,2 +286,5 @@

error.response = response;
error.data = data;
error.code = data.error_code;

@@ -249,0 +291,0 @@ error.retryAfter = data.parameters.retry_after;

@@ -52,7 +52,7 @@ //-----------------------------------------------------

function call(proxy, token, method, data, callback) {
if(!token) {
if(!token || typeof(token) !== "string") {
throw new Error("`token` was not specified");
}
if(!method) {
if(!method || typeof(method) !== "string") {
throw new Error("`method` was not specified");

@@ -243,2 +243,12 @@ }

case "certificate": {
let filename;
//--------]>
if(Array.isArray(input)) {
[filename, input] = input;
}
//--------]>
const isUri = input && typeof(input) === "string" ? input.match(reTgUri) : null;

@@ -283,3 +293,3 @@ const proto = isUri && isUri[0];

input = response;
sendFile();
sendFile(filename);
}

@@ -294,3 +304,3 @@ });

sendFile();
sendFile(filename);
}

@@ -356,3 +366,3 @@

function sendFile() {
function sendFile(filename) {
uncork(request);

@@ -362,7 +372,5 @@

if(Array.isArray(input)) {
const [filename, buf] = input;
if(Buffer.isBuffer(input)) {
request.write(makeFieldFile(field, filename));
request.write(buf);
request.write(input);

@@ -374,3 +382,3 @@ done();

const rs = own ? fs.createReadStream(input) : input;
const fn = getFilenameFromStream(rs);
const fn = filename || getFilenameFromStream(rs);

@@ -377,0 +385,0 @@ if(own) {

@@ -9,2 +9,4 @@ //-----------------------------------------------------

const client = require("./client");
const polling = require("./polling");
const download = require("./download");

@@ -33,2 +35,6 @@ //-----------------------------------------------------

if(arg[0] === "-") {
if(key) {
setOpt(key, true);
}
key = null;

@@ -50,2 +56,8 @@ name = arg.replace(/^-+/, "");

if(key) {
setOpt(key, true);
}
//------------]>
function setOpt(k, v) {

@@ -84,11 +96,55 @@ const t = k.split(/^d\./);

try {
let response = await client(token, method, data, proxy);
response = JSON.stringify(response || "", null, prettyJson ? " " : null);
if(cmdOptions.polling) {
const t = cmdOptions.polling === true ? token : cmdOptions.polling;
const {echo} = cmdOptions;
process.stdout.write(response);
polling(t, async function(data) {
printJson(data);
if(echo) {
printJson(await client(t, "sendMessage", {
"chat_id": data.message.from.id,
"text": formatJson(data)
}));
}
}).catch(function(error) {
this.stop();
delete error.response;
printError(error);
});
}
else if(cmdOptions.download) {
const t = cmdOptions.download === true ? token : cmdOptions.download;
const {
id, dir, name
} = cmdOptions;
printJson(await download(t, id, dir, name));
}
else {
printJson(await client(token, method, data, proxy));
}
}
catch(e) {
process.stderr.write(e.message);
process.stderr.write(e.stack);
printError(e);
}
}();
//-----------------------------------------------------
function printJson(data) {
process.stdout.write(formatJson(data) + "\r\n");
}
function printError(error) {
process.stderr.write(error.message);
process.stderr.write("\r\n");
process.stderr.write(error.stack);
process.stderr.write("\r\n");
}
function formatJson(data) {
return JSON.stringify(data || "", null, prettyJson ? " " : null);
}

@@ -8,14 +8,2 @@ //-----------------------------------------------------

const fs = require("fs");
const path = require("path");
const client = require("./client");
const {
getWebContent,
pump
} = require("./tools");
//-----------------------------------------------------
module.exports = entities;

@@ -22,0 +10,0 @@

@@ -13,2 +13,3 @@ //-----------------------------------------------------

const entities = require("./entities");
const markup = require("./markup");

@@ -20,2 +21,3 @@ //-----------------------------------------------------

client.entities = entities;
client.markup = markup;

@@ -22,0 +24,0 @@ //-----------------------------------------------------

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc