Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@azteam/telegram-api

Package Overview
Dependencies
Maintainers
1
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azteam/telegram-api - npm Package Compare versions

Comparing version 1.1.97 to 1.1.98

537

lib/TelegramMessageSender.js

@@ -34,3 +34,4 @@ "use strict";

function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var ignoreServiceErrors = ['No matching document found for id', 'Error: timeout of', 'Error: connect ECONNREFUSED', 'Error: connect ETIMEDOUT', 'Request failed with status code', 'socket hang up'];
var ignoreServiceErrors = ['No matching document found for id', 'Error: timeout of', 'Error: connect ECONNREFUSED', 'Error: connect ETIMEDOUT', 'Request failed with status code', 'socket hang up'],
ignoreTelegramErrors = ['specified new message content and reply markup are exactly the same as a current content and reply markup of the message', 'message to edit not found'];
var TelegramMessageSender = /*#__PURE__*/function () {

@@ -49,56 +50,128 @@ function TelegramMessageSender(token, successChannelId, errorChannelId) {

_createClass(TelegramMessageSender, [{
key: "retrySendSuccessMessage",
key: "retrySend",
value: function () {
var _retrySendSuccessMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(name, successMsg) {
var options,
messageId,
res,
_args = arguments;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
var _retrySend = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(asyncFunc) {
var retry, messageId, _loop, _ret;
return _regeneratorRuntime().wrap(function _callee$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
messageId = null;
retry = 5, messageId = null;
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
var res;
return _regeneratorRuntime().wrap(function _loop$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 3;
return asyncFunc();
case 3:
res = _context.sent;
if (!res.messageId) {
_context.next = 8;
break;
}
messageId = res.messageId;
_context.next = 15;
break;
case 8:
if (!(res.parameters && res.parameters.retry_after)) {
_context.next = 14;
break;
}
_context.next = 11;
return (0, _util.timeout)(res.parameters.retry_after * 1000);
case 11:
retry = 0;
_context.next = 15;
break;
case 14:
if (res.description) {
if (ignoreTelegramErrors.some(function (el) {
return res.description.message.includes(el);
})) {
retry = 0;
} else {
console.error(res.description);
}
} else {
console.error(res);
retry = false;
}
case 15:
return _context.abrupt("return", {
v: {
messageId: messageId,
retry: retry
}
});
case 18:
_context.prev = 18;
_context.t0 = _context["catch"](0);
retry -= 1;
_context.next = 23;
return (0, _util.timeout)(1000);
case 23:
case "end":
return _context.stop();
}
}, _loop, null, [[0, 18]]);
});
case 2:
if (messageId) {
_context.next = 18;
return _context2.delegateYield(_loop(), "t0", 3);
case 3:
_ret = _context2.t0;
if (!_ret) {
_context2.next = 6;
break;
}
_context.next = 5;
return this.sendSuccessMessage(name, successMsg, options);
case 5:
res = _context.sent;
if (!res.messageId) {
_context.next = 10;
return _context2.abrupt("return", _ret.v);
case 6:
if (retry) {
_context2.next = 2;
break;
}
messageId = res.messageId;
_context.next = 16;
break;
case 10:
if (!(res.parameters && res.parameters.retry_after)) {
_context.next = 15;
break;
}
_context.next = 13;
return (0, _util.timeout)(res.parameters.retry_after * 1000);
case 13:
_context.next = 16;
break;
case 15:
console.error(res);
case 16:
_context.next = 2;
break;
case 18:
return _context.abrupt("return", {
case 7:
return _context2.abrupt("return", {
messageId: messageId
});
case 19:
case 8:
case "end":
return _context.stop();
return _context2.stop();
}
}, _callee, this);
}, _callee);
}));
function retrySendSuccessMessage(_x, _x2) {
function retrySend(_x) {
return _retrySend.apply(this, arguments);
}
return retrySend;
}()
}, {
key: "retrySendSuccessMessage",
value: function () {
var _retrySendSuccessMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(name, successMsg) {
var _this = this;
var options,
_args4 = arguments;
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
options = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : {};
return _context4.abrupt("return", this.retrySend( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt("return", _this.sendSuccessMessage(name, successMsg, options));
case 1:
case "end":
return _context3.stop();
}
}, _callee2);
}))));
case 2:
case "end":
return _context4.stop();
}
}, _callee3, this);
}));
function retrySendSuccessMessage(_x2, _x3) {
return _retrySendSuccessMessage.apply(this, arguments);

@@ -111,54 +184,28 @@ }

value: function () {
var _retrySendErrorMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(name, errorMsg) {
var _retrySendErrorMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(name, errorMsg) {
var _this2 = this;
var options,
messageId,
res,
_args2 = arguments;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
_args6 = arguments;
return _regeneratorRuntime().wrap(function _callee5$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
messageId = null;
options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
return _context6.abrupt("return", this.retrySend( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
return _regeneratorRuntime().wrap(function _callee4$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
return _context5.abrupt("return", _this2.sendErrorMessage(name, errorMsg, options));
case 1:
case "end":
return _context5.stop();
}
}, _callee4);
}))));
case 2:
if (messageId) {
_context2.next = 18;
break;
}
_context2.next = 5;
return this.sendErrorMessage(name, errorMsg, options);
case 5:
res = _context2.sent;
if (!res.messageId) {
_context2.next = 10;
break;
}
messageId = res.messageId;
_context2.next = 16;
break;
case 10:
if (!(res.parameters && res.parameters.retry_after)) {
_context2.next = 15;
break;
}
_context2.next = 13;
return (0, _util.timeout)(res.parameters.retry_after * 1000);
case 13:
_context2.next = 16;
break;
case 15:
console.error(res);
case 16:
_context2.next = 2;
break;
case 18:
return _context2.abrupt("return", {
messageId: messageId
});
case 19:
case "end":
return _context2.stop();
return _context6.stop();
}
}, _callee2, this);
}, _callee5, this);
}));
function retrySendErrorMessage(_x3, _x4) {
function retrySendErrorMessage(_x4, _x5) {
return _retrySendErrorMessage.apply(this, arguments);

@@ -171,54 +218,28 @@ }

value: function () {
var _retrySendChatMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(userId, name, msg) {
var _retrySendChatMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(userId, name, msg) {
var _this3 = this;
var options,
messageId,
res,
_args3 = arguments;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
_args8 = arguments;
return _regeneratorRuntime().wrap(function _callee7$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
options = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : {};
messageId = null;
options = _args8.length > 3 && _args8[3] !== undefined ? _args8[3] : {};
return _context8.abrupt("return", this.retrySend( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
return _regeneratorRuntime().wrap(function _callee6$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
return _context7.abrupt("return", _this3.sendChatMessage(name, msg, options));
case 1:
case "end":
return _context7.stop();
}
}, _callee6);
}))));
case 2:
if (messageId) {
_context3.next = 18;
break;
}
_context3.next = 5;
return this.sendChatMessage(name, msg, options);
case 5:
res = _context3.sent;
if (!res.messageId) {
_context3.next = 10;
break;
}
messageId = res.messageId;
_context3.next = 16;
break;
case 10:
if (!(res.parameters && res.parameters.retry_after)) {
_context3.next = 15;
break;
}
_context3.next = 13;
return (0, _util.timeout)(res.parameters.retry_after * 1000);
case 13:
_context3.next = 16;
break;
case 15:
console.error(res);
case 16:
_context3.next = 2;
break;
case 18:
return _context3.abrupt("return", {
messageId: messageId
});
case 19:
case "end":
return _context3.stop();
return _context8.stop();
}
}, _callee3, this);
}, _callee7, this);
}));
function retrySendChatMessage(_x5, _x6, _x7) {
function retrySendChatMessage(_x6, _x7, _x8) {
return _retrySendChatMessage.apply(this, arguments);

@@ -231,3 +252,3 @@ }

value: function () {
var _sendErrorApiMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(error, url) {
var _sendErrorApiMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(error, url) {
var replyId,

@@ -239,12 +260,12 @@ messageId,

res,
_args4 = arguments;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
_args9 = arguments;
return _regeneratorRuntime().wrap(function _callee8$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
replyId = _args4.length > 2 && _args4[2] !== undefined ? _args4[2] : null;
replyId = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : null;
console.error(error);
messageId = null;
_context4.prev = 3;
_context9.prev = 3;
if (!(_typeof(error) === 'object' && error.errors && error.errors[0])) {
_context4.next = 20;
_context9.next = 20;
break;

@@ -254,3 +275,3 @@ }

if (!(process.env.NODE_ENV === 'development' && firstError.code === _error.INVALID || firstError.code === _error.UNKNOWN)) {
_context4.next = 20;
_context9.next = 20;
break;

@@ -261,3 +282,3 @@ }

}))) {
_context4.next = 20;
_context9.next = 20;
break;

@@ -267,18 +288,18 @@ }

if (!replyId) {
_context4.next = 15;
_context9.next = 15;
break;
}
_context4.next = 12;
_context9.next = 12;
return this.api.sendReplyInboxMessage(this.errorChannelId, replyId, errorMessage);
case 12:
_context4.t0 = _context4.sent;
_context4.next = 18;
_context9.t0 = _context9.sent;
_context9.next = 18;
break;
case 15:
_context4.next = 17;
_context9.next = 17;
return this.api.sendInboxMessage(this.errorChannelId, errorMessage);
case 17:
_context4.t0 = _context4.sent;
_context9.t0 = _context9.sent;
case 18:
res = _context4.t0;
res = _context9.t0;
if (res.result) {

@@ -290,10 +311,10 @@ messageId = res.result.message_id;

case 20:
_context4.next = 25;
_context9.next = 25;
break;
case 22:
_context4.prev = 22;
_context4.t1 = _context4["catch"](3);
_context9.prev = 22;
_context9.t1 = _context9["catch"](3);
console.error('sendErrorApiMessage', error);
case 25:
return _context4.abrupt("return", {
return _context9.abrupt("return", {
messageId: messageId

@@ -303,7 +324,7 @@ });

case "end":
return _context4.stop();
return _context9.stop();
}
}, _callee4, this, [[3, 22]]);
}, _callee8, this, [[3, 22]]);
}));
function sendErrorApiMessage(_x8, _x9) {
function sendErrorApiMessage(_x9, _x10) {
return _sendErrorApiMessage.apply(this, arguments);

@@ -316,3 +337,3 @@ }

value: function () {
var _sendErrorMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(name) {
var _sendErrorMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(name) {
var errorMsg,

@@ -325,10 +346,10 @@ options,

res,
_args5 = arguments;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
_args10 = arguments;
return _regeneratorRuntime().wrap(function _callee9$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
errorMsg = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : '';
options = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : {};
errorMsg = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : '';
options = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : {};
console.error(errorMsg);
_context5.prev = 3;
_context10.prev = 3;
errorString = errorMsg.toString();

@@ -338,3 +359,3 @@ if (ignoreServiceErrors.some(function (el) {

})) {
_context5.next = 26;
_context10.next = 26;
break;

@@ -345,53 +366,53 @@ }

if (!replyId) {
_context5.next = 14;
_context10.next = 14;
break;
}
_context5.next = 11;
_context10.next = 11;
return this.api.sendReplyInboxMessage(this.errorChannelId, replyId, errorMessage);
case 11:
res = _context5.sent;
_context5.next = 23;
res = _context10.sent;
_context10.next = 23;
break;
case 14:
if (!editId) {
_context5.next = 20;
_context10.next = 20;
break;
}
_context5.next = 17;
_context10.next = 17;
return this.api.sendEditMessage(this.errorChannelId, replyId, errorMessage);
case 17:
res = _context5.sent;
_context5.next = 23;
res = _context10.sent;
_context10.next = 23;
break;
case 20:
_context5.next = 22;
_context10.next = 22;
return this.api.sendInboxMessage(this.errorChannelId, errorMessage);
case 22:
res = _context5.sent;
res = _context10.sent;
case 23:
if (!(res && res.result)) {
_context5.next = 25;
_context10.next = 25;
break;
}
return _context5.abrupt("return", {
return _context10.abrupt("return", {
messageId: res.result.message_id
});
case 25:
return _context5.abrupt("return", res);
return _context10.abrupt("return", res);
case 26:
_context5.next = 31;
_context10.next = 31;
break;
case 28:
_context5.prev = 28;
_context5.t0 = _context5["catch"](3);
_context10.prev = 28;
_context10.t0 = _context10["catch"](3);
console.error('sendErrorMessage', errorMsg);
case 31:
return _context5.abrupt("return", {});
return _context10.abrupt("return", {});
case 32:
case "end":
return _context5.stop();
return _context10.stop();
}
}, _callee5, this, [[3, 28]]);
}, _callee9, this, [[3, 28]]);
}));
function sendErrorMessage(_x10) {
function sendErrorMessage(_x11) {
return _sendErrorMessage.apply(this, arguments);

@@ -404,3 +425,3 @@ }

value: function () {
var _sendSuccessMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(name) {
var _sendSuccessMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(name) {
var successMsg,

@@ -413,16 +434,16 @@ options,

res,
_args6 = arguments;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
_args11 = arguments;
return _regeneratorRuntime().wrap(function _callee10$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
successMsg = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : '';
options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
_context6.prev = 2;
successMsg = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : '';
options = _args11.length > 2 && _args11[2] !== undefined ? _args11[2] : {};
_context11.prev = 2;
replyId = options.replyId, editId = options.editId, opt = _objectWithoutProperties(options, _excluded), successMessage = "<b>".concat(name, "</b>\n").concat(successMsg);
res = null;
if (!replyId) {
_context6.next = 11;
_context11.next = 11;
break;
}
_context6.next = 8;
_context11.next = 8;
return this.api.sendReplyInboxMessage(this.successChannelId, replyId, successMessage, _objectSpread({

@@ -432,18 +453,18 @@ disable_notification: true

case 8:
res = _context6.sent;
_context6.next = 20;
res = _context11.sent;
_context11.next = 20;
break;
case 11:
if (!editId) {
_context6.next = 17;
_context11.next = 17;
break;
}
_context6.next = 14;
_context11.next = 14;
return this.api.sendEditMessage(this.successChannelId, editId, successMessage);
case 14:
res = _context6.sent;
_context6.next = 20;
res = _context11.sent;
_context11.next = 20;
break;
case 17:
_context6.next = 19;
_context11.next = 19;
return this.api.sendInboxMessage(this.successChannelId, successMessage, _objectSpread({

@@ -453,26 +474,26 @@ disable_notification: true

case 19:
res = _context6.sent;
res = _context11.sent;
case 20:
if (!(res && res.result)) {
_context6.next = 22;
_context11.next = 22;
break;
}
return _context6.abrupt("return", {
return _context11.abrupt("return", {
messageId: res.result.message_id
});
case 22:
return _context6.abrupt("return", res);
return _context11.abrupt("return", res);
case 25:
_context6.prev = 25;
_context6.t0 = _context6["catch"](2);
console.error('sendSuccessMessage', successMsg, _context6.t0);
_context11.prev = 25;
_context11.t0 = _context11["catch"](2);
console.error('sendSuccessMessage', successMsg, _context11.t0);
case 28:
return _context6.abrupt("return", {});
return _context11.abrupt("return", {});
case 29:
case "end":
return _context6.stop();
return _context11.stop();
}
}, _callee6, this, [[2, 25]]);
}, _callee10, this, [[2, 25]]);
}));
function sendSuccessMessage(_x11) {
function sendSuccessMessage(_x12) {
return _sendSuccessMessage.apply(this, arguments);

@@ -485,3 +506,3 @@ }

value: function () {
var _sendChatMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(userId, name) {
var _sendChatMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(userId, name) {
var msg,

@@ -494,16 +515,16 @@ options,

res,
_args7 = arguments;
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
_args12 = arguments;
return _regeneratorRuntime().wrap(function _callee11$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
msg = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : '';
options = _args7.length > 3 && _args7[3] !== undefined ? _args7[3] : {};
_context7.prev = 2;
msg = _args12.length > 2 && _args12[2] !== undefined ? _args12[2] : '';
options = _args12.length > 3 && _args12[3] !== undefined ? _args12[3] : {};
_context12.prev = 2;
replyId = options.replyId, editId = options.editId, opt = _objectWithoutProperties(options, _excluded2), successMessage = "<b>".concat(name, "</b>\n").concat(msg);
res = null;
if (!replyId) {
_context7.next = 11;
_context12.next = 11;
break;
}
_context7.next = 8;
_context12.next = 8;
return this.api.sendReplyInboxMessage(userId, replyId, successMessage, _objectSpread({

@@ -513,18 +534,18 @@ disable_notification: true

case 8:
res = _context7.sent;
_context7.next = 20;
res = _context12.sent;
_context12.next = 20;
break;
case 11:
if (!editId) {
_context7.next = 17;
_context12.next = 17;
break;
}
_context7.next = 14;
_context12.next = 14;
return this.api.sendEditMessage(userId, editId, successMessage);
case 14:
res = _context7.sent;
_context7.next = 20;
res = _context12.sent;
_context12.next = 20;
break;
case 17:
_context7.next = 19;
_context12.next = 19;
return this.api.sendInboxMessage(userId, successMessage, _objectSpread({

@@ -534,26 +555,26 @@ disable_notification: true

case 19:
res = _context7.sent;
res = _context12.sent;
case 20:
if (!(res && res.result)) {
_context7.next = 22;
_context12.next = 22;
break;
}
return _context7.abrupt("return", {
return _context12.abrupt("return", {
messageId: res.result.message_id
});
case 22:
return _context7.abrupt("return", res);
return _context12.abrupt("return", res);
case 25:
_context7.prev = 25;
_context7.t0 = _context7["catch"](2);
console.error('sendChatMessage', msg, _context7.t0);
_context12.prev = 25;
_context12.t0 = _context12["catch"](2);
console.error('sendChatMessage', msg, _context12.t0);
case 28:
return _context7.abrupt("return", {});
return _context12.abrupt("return", {});
case 29:
case "end":
return _context7.stop();
return _context12.stop();
}
}, _callee7, this, [[2, 25]]);
}, _callee11, this, [[2, 25]]);
}));
function sendChatMessage(_x12, _x13) {
function sendChatMessage(_x13, _x14) {
return _sendChatMessage.apply(this, arguments);

@@ -566,12 +587,12 @@ }

value: function () {
var _sendSuccessFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(file, message) {
var _sendSuccessFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(file, message) {
var replyID,
res,
_args8 = arguments;
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
_args13 = arguments;
return _regeneratorRuntime().wrap(function _callee12$(_context13) {
while (1) switch (_context13.prev = _context13.next) {
case 0:
replyID = _args8.length > 2 && _args8[2] !== undefined ? _args8[2] : null;
_context8.prev = 1;
_context8.next = 4;
replyID = _args13.length > 2 && _args13[2] !== undefined ? _args13[2] : null;
_context13.prev = 1;
_context13.next = 4;
return this.api.sendFileBuffer(this.successChannelId, file, _path["default"].basename(file), {

@@ -582,25 +603,25 @@ caption: message,

case 4:
res = _context8.sent;
res = _context13.sent;
if (!res.result) {
_context8.next = 7;
_context13.next = 7;
break;
}
return _context8.abrupt("return", {
return _context13.abrupt("return", {
messageId: res.result.message_id
});
case 7:
return _context8.abrupt("return", res);
return _context13.abrupt("return", res);
case 10:
_context8.prev = 10;
_context8.t0 = _context8["catch"](1);
console.error('sendSuccessFile', file, _context8.t0);
_context13.prev = 10;
_context13.t0 = _context13["catch"](1);
console.error('sendSuccessFile', file, _context13.t0);
case 13:
return _context8.abrupt("return", {});
return _context13.abrupt("return", {});
case 14:
case "end":
return _context8.stop();
return _context13.stop();
}
}, _callee8, this, [[1, 10]]);
}, _callee12, this, [[1, 10]]);
}));
function sendSuccessFile(_x14, _x15) {
function sendSuccessFile(_x15, _x16) {
return _sendSuccessFile.apply(this, arguments);

@@ -607,0 +628,0 @@ }

{
"name": "@azteam/telegram-api",
"version": "1.1.97",
"version": "1.1.98",
"description": "N/A",

@@ -5,0 +5,0 @@ "keywords": [

@@ -9,9 +9,13 @@ import path from 'path';

const ignoreServiceErrors = [
'No matching document found for id',
'Error: timeout of',
'Error: connect ECONNREFUSED',
'Error: connect ETIMEDOUT',
'Request failed with status code',
'socket hang up',
];
'No matching document found for id',
'Error: timeout of',
'Error: connect ECONNREFUSED',
'Error: connect ETIMEDOUT',
'Request failed with status code',
'socket hang up',
],
ignoreTelegramErrors = [
'specified new message content and reply markup are exactly the same as a current content and reply markup of the message',
'message to edit not found',
];

@@ -31,51 +35,51 @@ class TelegramMessageSender {

async retrySendSuccessMessage(name, successMsg, options = {}) {
let messageId = null;
while (!messageId) {
const res = await this.sendSuccessMessage(name, successMsg, options);
if (res.messageId) {
messageId = res.messageId;
} else if (res.parameters && res.parameters.retry_after) {
await timeout(res.parameters.retry_after * 1000);
} else {
console.error(res);
async retrySend(asyncFunc) {
let retry = 5,
messageId = null;
do {
try {
const res = await asyncFunc();
if (res.messageId) {
messageId = res.messageId;
} else if (res.parameters && res.parameters.retry_after) {
await timeout(res.parameters.retry_after * 1000);
retry = 0;
} else if (res.description) {
if (ignoreTelegramErrors.some((el) => res.description.message.includes(el))) {
retry = 0;
} else {
console.error(res.description);
}
} else {
console.error(res);
retry = false;
}
return {messageId, retry};
} catch (err) {
retry -= 1;
await timeout(1000);
}
}
} while (retry);
return {messageId};
return {
messageId,
};
}
async retrySendSuccessMessage(name, successMsg, options = {}) {
return this.retrySend(async () => {
return this.sendSuccessMessage(name, successMsg, options);
});
}
async retrySendErrorMessage(name, errorMsg, options = {}) {
let messageId = null;
while (!messageId) {
const res = await this.sendErrorMessage(name, errorMsg, options);
if (res.messageId) {
messageId = res.messageId;
} else if (res.parameters && res.parameters.retry_after) {
await timeout(res.parameters.retry_after * 1000);
} else {
console.error(res);
}
}
return {messageId};
return this.retrySend(async () => {
return this.sendErrorMessage(name, errorMsg, options);
});
}
async retrySendChatMessage(userId, name, msg, options = {}) {
let messageId = null;
while (!messageId) {
const res = await this.sendChatMessage(name, msg, options);
if (res.messageId) {
messageId = res.messageId;
} else if (res.parameters && res.parameters.retry_after) {
await timeout(res.parameters.retry_after * 1000);
} else {
console.error(res);
}
}
return {messageId};
return this.retrySend(async () => {
return this.sendChatMessage(name, msg, options);
});
}

@@ -82,0 +86,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc