Browse Source

add missing attributes to send file.
fix uploading photos

painor 4 years ago
parent
commit
9dd52f2658
3 changed files with 36 additions and 5 deletions
  1. 33 2
      gramjs/client/uploads.ts
  2. 2 2
      package-lock.json
  3. 1 1
      package.json

+ 33 - 2
gramjs/client/uploads.ts

@@ -145,15 +145,42 @@ export interface SendFileInterface {
     voiceNote?: boolean,
     videoNote?: boolean,
     supportStreaming?: boolean,
+    parseMode?: any,
+    formattingEntities?: Api.TypeMessageEntity[],
+    silent?: boolean;
+    background?: boolean;
+    clearDraft?: boolean;
+    replyMarkup?: Api.TypeReplyMarkup;
+    scheduleDate?: number;
+
 }
 
-export async function sendFile(client: TelegramClient, entity: EntityLike, {file, caption, forceDocument, fileSize, progressCallback, replyTo, attributes, thumb, voiceNote, videoNote, supportStreaming}: SendFileInterface) {
+export async function sendFile(client: TelegramClient, entity: EntityLike,
+                               {   file,
+                                   caption,
+                                   forceDocument,
+                                   fileSize,
+                                   progressCallback,
+                                   replyTo,
+                                   attributes,
+                                   thumb, voiceNote,
+                                   videoNote,
+                                   supportStreaming,
+                                   parseMode, formattingEntities,
+                                   scheduleDate,
+                                   replyMarkup,
+                                   clearDraft,
+                               }: SendFileInterface) {
     if (!file) {
         throw new Error("You need to specify a file");
     }
     if (!caption) {
         caption = ""
     }
+    if (formattingEntities == undefined) {
+        [caption, formattingEntities] = await client._parseMessageText(caption, parseMode);
+    }
+
     if (typeof file == "string") {
         file = new CustomFile(path.basename(file), fs.statSync(file).size, file);
     }
@@ -179,7 +206,7 @@ export async function sendFile(client: TelegramClient, entity: EntityLike, {file
         attributes.push(...result.attrs);
     }
     let toSend;
-    if (mimeType.startsWith("photo/")) {
+    if (mimeType.startsWith("photo/") || mimeType.startsWith("image/")) {
         toSend = new Api.InputMediaUploadedPhoto({
             file: media,
         })
@@ -196,6 +223,10 @@ export async function sendFile(client: TelegramClient, entity: EntityLike, {file
         media: toSend,
         replyToMsgId: replyTo,
         message: caption,
+        entities:formattingEntities,
+        scheduleDate,
+        replyMarkup,
+        clearDraft,
     }));
     // TODO get result
     return result;

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "telegram",
-  "version": "1.6.0",
+  "version": "1.6.1",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "telegram",
-      "version": "1.6.0",
+      "version": "1.6.1",
       "license": "MIT",
       "dependencies": {
         "@cryptography/aes": "^0.1.1",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "telegram",
-  "version": "1.6.0",
+  "version": "1.6.1",
   "description": "NodeJS MTProto API Telegram client library,",
   "main": "index.js",
   "types": "index.d.ts",