@builderbot/provider-telegram 1.3.15-alpha.18 → 1.3.15-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +30 -19
- package/package.json +7 -4
package/dist/index.cjs
CHANGED
|
@@ -47885,7 +47885,6 @@ class TelegramEvents extends bot$1.EventEmitterClass {
|
|
|
47885
47885
|
const isVoice = payload.message.voice ? true : false;
|
|
47886
47886
|
const mimeType = hasFile ? payload.message.file.mimeType : null;
|
|
47887
47887
|
const sendObj = {
|
|
47888
|
-
...payload,
|
|
47889
47888
|
body: payload.message.message,
|
|
47890
47889
|
caption: payload.message.message,
|
|
47891
47890
|
from: payload.chatId.toString(),
|
|
@@ -47894,6 +47893,11 @@ class TelegramEvents extends bot$1.EventEmitterClass {
|
|
|
47894
47893
|
hasFile,
|
|
47895
47894
|
isVoice,
|
|
47896
47895
|
mimeType,
|
|
47896
|
+
message: {
|
|
47897
|
+
voice: !!payload.message.voice,
|
|
47898
|
+
media: !!payload.message.media,
|
|
47899
|
+
message: payload.message.message,
|
|
47900
|
+
},
|
|
47897
47901
|
};
|
|
47898
47902
|
this.emit('message', sendObj);
|
|
47899
47903
|
};
|
|
@@ -47927,6 +47931,10 @@ class TelegramProvider extends bot$1.ProviderClass {
|
|
|
47927
47931
|
const stringSession = this._getStringSession();
|
|
47928
47932
|
this.client = new telegramExports.TelegramClient(stringSession, +args.apiId, args.apiHash, {
|
|
47929
47933
|
connectionRetries: 5,
|
|
47934
|
+
useWSS: true,
|
|
47935
|
+
deviceModel: 'BuilderBot Server',
|
|
47936
|
+
systemVersion: 'Node.js',
|
|
47937
|
+
appVersion: '1.0.0',
|
|
47930
47938
|
});
|
|
47931
47939
|
}
|
|
47932
47940
|
_getStringSession() {
|
|
@@ -47942,9 +47950,9 @@ class TelegramProvider extends bot$1.ProviderClass {
|
|
|
47942
47950
|
return await this.sendButtons(userId, message, args?.buttons);
|
|
47943
47951
|
if (args?.mediaURL)
|
|
47944
47952
|
return await this.sendMedia(userId, args?.mediaURL, message);
|
|
47945
|
-
await this.client.sendMessage(userId, {
|
|
47953
|
+
return (await this.client.sendMessage(userId, {
|
|
47946
47954
|
message,
|
|
47947
|
-
});
|
|
47955
|
+
}));
|
|
47948
47956
|
}
|
|
47949
47957
|
async getUnreadMessages(args) {
|
|
47950
47958
|
const mySenderId = (await this.client.getMe()).id.toString();
|
|
@@ -47954,6 +47962,8 @@ class TelegramProvider extends bot$1.ProviderClass {
|
|
|
47954
47962
|
const messages = await this.client.getMessages(dialog.inputEntity, {
|
|
47955
47963
|
limit: dialog.unreadCount,
|
|
47956
47964
|
});
|
|
47965
|
+
if (!messages.length)
|
|
47966
|
+
continue;
|
|
47957
47967
|
if (messages[0].senderId.toString() == mySenderId)
|
|
47958
47968
|
continue;
|
|
47959
47969
|
const filteredMessages = messages.filter((msg) => msg.senderId.toString() !== mySenderId).reverse();
|
|
@@ -47988,7 +47998,11 @@ class TelegramProvider extends bot$1.ProviderClass {
|
|
|
47988
47998
|
const res = await fetch(mediaURL, { method: 'GET' });
|
|
47989
47999
|
const buffer = await res.arrayBuffer();
|
|
47990
48000
|
const mimeType = res.headers.get('content-type');
|
|
48001
|
+
if (!mimeType) {
|
|
48002
|
+
throw new Error(`[sendMedia] Unable to determine content-type for URL: ${mediaURL}`);
|
|
48003
|
+
}
|
|
47991
48004
|
const tmpDir = require$$0$7.join(process.cwd(), 'tmp', 'media');
|
|
48005
|
+
fs$1.mkdirSync(tmpDir, { recursive: true });
|
|
47992
48006
|
const fileExtension = mimeType.split('/')[1];
|
|
47993
48007
|
const fileName = `${Date.now().toString()}-${chatId}.${fileExtension}`;
|
|
47994
48008
|
let filePath = require$$0$7.join(tmpDir, fileName);
|
|
@@ -47997,17 +48011,18 @@ class TelegramProvider extends bot$1.ProviderClass {
|
|
|
47997
48011
|
let videoNote = false;
|
|
47998
48012
|
if (caption == 'video_note' && fileExtension == 'mp4') {
|
|
47999
48013
|
videoNote = true;
|
|
48000
|
-
const oldFilePath = filePath;
|
|
48001
|
-
filePath = require$$0$7.join(tmpDir, `new_${fileName}`);
|
|
48002
|
-
fs$1.unlinkSync(oldFilePath);
|
|
48003
48014
|
}
|
|
48004
|
-
|
|
48005
|
-
|
|
48006
|
-
|
|
48007
|
-
|
|
48008
|
-
|
|
48009
|
-
|
|
48010
|
-
|
|
48015
|
+
try {
|
|
48016
|
+
await this.client.sendFile(chatId, {
|
|
48017
|
+
file: filePath,
|
|
48018
|
+
voiceNote,
|
|
48019
|
+
caption,
|
|
48020
|
+
videoNote,
|
|
48021
|
+
});
|
|
48022
|
+
}
|
|
48023
|
+
finally {
|
|
48024
|
+
fs$1.unlinkSync(filePath);
|
|
48025
|
+
}
|
|
48011
48026
|
return;
|
|
48012
48027
|
}
|
|
48013
48028
|
beforeHttpServerInit() { }
|
|
@@ -48030,15 +48045,10 @@ class TelegramProvider extends bot$1.ProviderClass {
|
|
|
48030
48045
|
async initVendor() {
|
|
48031
48046
|
const vendor = new TelegramEvents();
|
|
48032
48047
|
this.vendor = vendor;
|
|
48033
|
-
console.log(`[phoneNumber] ${this.globalVendorArgs.apiNumber}`);
|
|
48034
|
-
console.log(`[phoneCode] ${this.globalVendorArgs.apiPassword}`);
|
|
48035
|
-
console.log(`[password] ${this.globalVendorArgs.apiPassword}`);
|
|
48036
48048
|
await this.client.start({
|
|
48037
48049
|
phoneNumber: async () => this.globalVendorArgs.apiNumber,
|
|
48038
48050
|
phoneCode: async () => {
|
|
48039
|
-
|
|
48040
|
-
await bot$1.utils.delay(10000);
|
|
48041
|
-
return new Promise((resolve) => resolve(code));
|
|
48051
|
+
return await this.globalVendorArgs.getCode();
|
|
48042
48052
|
},
|
|
48043
48053
|
password: async () => this.globalVendorArgs.apiPassword || '',
|
|
48044
48054
|
onError: (err) => console.log(err),
|
|
@@ -48069,6 +48079,7 @@ class TelegramProvider extends bot$1.ProviderClass {
|
|
|
48069
48079
|
}
|
|
48070
48080
|
catch (error) {
|
|
48071
48081
|
console.error('[saveFile()]', error);
|
|
48082
|
+
return '';
|
|
48072
48083
|
}
|
|
48073
48084
|
}
|
|
48074
48085
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builderbot/provider-telegram",
|
|
3
|
-
"version": "1.3.15-alpha.
|
|
3
|
+
"version": "1.3.15-alpha.19",
|
|
4
4
|
"description": "Provider for Telegram",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/codigoencasa/bot-whatsapp#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@builderbot/bot": "^1.3.15-alpha.
|
|
32
|
+
"@builderbot/bot": "^1.3.15-alpha.19",
|
|
33
33
|
"@hapi/boom": "^10.0.1",
|
|
34
34
|
"@jest/globals": "^30.2.0",
|
|
35
35
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
@@ -41,10 +41,13 @@
|
|
|
41
41
|
"@types/node": "^24.10.2",
|
|
42
42
|
"@types/qr-image": "^3.2.9",
|
|
43
43
|
"@types/sinon": "^17.0.3",
|
|
44
|
-
"
|
|
44
|
+
"jest": "^30.2.0",
|
|
45
|
+
"rimraf": "^6.1.2",
|
|
46
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
47
|
+
"ts-jest": "^29.4.6"
|
|
45
48
|
},
|
|
46
49
|
"dependencies": {
|
|
47
50
|
"telegram": "^2.23.10"
|
|
48
51
|
},
|
|
49
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "3107ed12c78384a885ca484330993fd31013a631"
|
|
50
53
|
}
|