@builderbot/provider-telegram 1.3.15-alpha.2 → 1.3.15-alpha.20

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.
Files changed (2) hide show
  1. package/dist/index.cjs +46 -19
  2. package/package.json +10 -5
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();
@@ -47981,6 +47991,22 @@ class TelegramProvider extends bot$1.ProviderClass {
47981
47991
  async markAsRead(from) {
47982
47992
  await this.client.markAsRead(from);
47983
47993
  }
47994
+ async sendPresenceUpdate(chatId, action = 'typing') {
47995
+ let typingAction;
47996
+ if (action === 'recording') {
47997
+ typingAction = new telegramExports.Api.SendMessageRecordAudioAction();
47998
+ }
47999
+ else if (action === 'cancel') {
48000
+ typingAction = new telegramExports.Api.SendMessageCancelAction();
48001
+ }
48002
+ else {
48003
+ typingAction = new telegramExports.Api.SendMessageTypingAction();
48004
+ }
48005
+ await this.client.invoke(new telegramExports.Api.messages.SetTyping({
48006
+ peer: chatId,
48007
+ action: typingAction,
48008
+ }));
48009
+ }
47984
48010
  async sendButtons(chatId, text, buttons) {
47985
48011
  return;
47986
48012
  }
@@ -47988,7 +48014,11 @@ class TelegramProvider extends bot$1.ProviderClass {
47988
48014
  const res = await fetch(mediaURL, { method: 'GET' });
47989
48015
  const buffer = await res.arrayBuffer();
47990
48016
  const mimeType = res.headers.get('content-type');
48017
+ if (!mimeType) {
48018
+ throw new Error(`[sendMedia] Unable to determine content-type for URL: ${mediaURL}`);
48019
+ }
47991
48020
  const tmpDir = require$$0$7.join(process.cwd(), 'tmp', 'media');
48021
+ fs$1.mkdirSync(tmpDir, { recursive: true });
47992
48022
  const fileExtension = mimeType.split('/')[1];
47993
48023
  const fileName = `${Date.now().toString()}-${chatId}.${fileExtension}`;
47994
48024
  let filePath = require$$0$7.join(tmpDir, fileName);
@@ -47997,17 +48027,18 @@ class TelegramProvider extends bot$1.ProviderClass {
47997
48027
  let videoNote = false;
47998
48028
  if (caption == 'video_note' && fileExtension == 'mp4') {
47999
48029
  videoNote = true;
48000
- const oldFilePath = filePath;
48001
- filePath = require$$0$7.join(tmpDir, `new_${fileName}`);
48002
- fs$1.unlinkSync(oldFilePath);
48003
48030
  }
48004
- await this.client.sendFile(chatId, {
48005
- file: filePath,
48006
- voiceNote,
48007
- caption,
48008
- videoNote,
48009
- });
48010
- fs$1.unlinkSync(filePath);
48031
+ try {
48032
+ await this.client.sendFile(chatId, {
48033
+ file: filePath,
48034
+ voiceNote,
48035
+ caption,
48036
+ videoNote,
48037
+ });
48038
+ }
48039
+ finally {
48040
+ fs$1.unlinkSync(filePath);
48041
+ }
48011
48042
  return;
48012
48043
  }
48013
48044
  beforeHttpServerInit() { }
@@ -48030,15 +48061,10 @@ class TelegramProvider extends bot$1.ProviderClass {
48030
48061
  async initVendor() {
48031
48062
  const vendor = new TelegramEvents();
48032
48063
  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
48064
  await this.client.start({
48037
48065
  phoneNumber: async () => this.globalVendorArgs.apiNumber,
48038
48066
  phoneCode: async () => {
48039
- const code = await this.globalVendorArgs.getCode();
48040
- await bot$1.utils.delay(10000);
48041
- return new Promise((resolve) => resolve(code));
48067
+ return await this.globalVendorArgs.getCode();
48042
48068
  },
48043
48069
  password: async () => this.globalVendorArgs.apiPassword || '',
48044
48070
  onError: (err) => console.log(err),
@@ -48069,6 +48095,7 @@ class TelegramProvider extends bot$1.ProviderClass {
48069
48095
  }
48070
48096
  catch (error) {
48071
48097
  console.error('[saveFile()]', error);
48098
+ return '';
48072
48099
  }
48073
48100
  }
48074
48101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builderbot/provider-telegram",
3
- "version": "1.3.15-alpha.2",
3
+ "version": "1.3.15-alpha.20",
4
4
  "description": "Provider for Telegram",
5
5
  "keywords": [],
6
6
  "author": "",
@@ -9,7 +9,9 @@
9
9
  "types": "dist/index.d.ts",
10
10
  "type": "module",
11
11
  "scripts": {
12
- "build": "rimraf dist && rollup --config"
12
+ "build": "rimraf dist && rollup --config",
13
+ "test": "jest --forceExit",
14
+ "test:coverage": "jest --coverage"
13
15
  },
14
16
  "files": [
15
17
  "./dist/"
@@ -27,7 +29,7 @@
27
29
  },
28
30
  "homepage": "https://github.com/codigoencasa/bot-whatsapp#readme",
29
31
  "devDependencies": {
30
- "@builderbot/bot": "1.3.15-alpha.2",
32
+ "@builderbot/bot": "^1.3.15-alpha.20",
31
33
  "@hapi/boom": "^10.0.1",
32
34
  "@jest/globals": "^30.2.0",
33
35
  "@rollup/plugin-commonjs": "^29.0.0",
@@ -39,10 +41,13 @@
39
41
  "@types/node": "^24.10.2",
40
42
  "@types/qr-image": "^3.2.9",
41
43
  "@types/sinon": "^17.0.3",
42
- "rollup-plugin-typescript2": "^0.36.0"
44
+ "jest": "^30.2.0",
45
+ "rimraf": "^6.1.2",
46
+ "rollup-plugin-typescript2": "^0.36.0",
47
+ "ts-jest": "^29.4.6"
43
48
  },
44
49
  "dependencies": {
45
50
  "telegram": "^2.23.10"
46
51
  },
47
- "gitHead": "6fe2b64bd3006f6f4805ac0ff36c616a3b91fa09"
52
+ "gitHead": "9e42f89f192af0c70931241e820e726f822dd9cc"
48
53
  }