typescript-telegram-bot-api
Advanced tools
Comparing version 0.1.10 to 0.1.11
@@ -11,2 +11,3 @@ "use strict"; | ||
const util_1 = require("util"); | ||
const stream_1 = require("stream"); | ||
const errors_1 = require("./errors"); | ||
@@ -35,20 +36,3 @@ const pooling_1 = require("./pooling"); | ||
return new Promise((resolve, reject) => { | ||
const formData = new form_data_1.default(); | ||
if (options) | ||
Object.keys(options).forEach((key) => { | ||
if (options[key] !== undefined) { | ||
if (typeof options[key] === 'boolean') { | ||
formData.append(key, String(options[key])); | ||
} | ||
else if (options[key] instanceof Buffer) { | ||
formData.append(key, options[key], { | ||
filename: 'file', | ||
contentType: 'application/octet-stream', | ||
}); | ||
} | ||
else { | ||
formData.append(key, options[key]); | ||
} | ||
} | ||
}); | ||
const formData = this.createFormData(options); | ||
const request = https_1.default.request(url, { | ||
@@ -81,2 +65,29 @@ method: 'POST', | ||
} | ||
createFormData(options) { | ||
const formData = new form_data_1.default(); | ||
if (options) { | ||
for (const [key, value] of Object.entries(options)) { | ||
if (value !== undefined) { | ||
if (typeof options[key] === 'boolean') { | ||
formData.append(key, String(options[key])); | ||
} | ||
else if (options[key] instanceof Buffer) { | ||
formData.append(key, options[key], { | ||
filename: 'file', | ||
contentType: 'application/octet-stream', | ||
}); | ||
} | ||
else if (typeof options[key] === 'object' && | ||
!Array.isArray(options[key]) && | ||
!(options[key] instanceof stream_1.Readable)) { | ||
formData.append(key, JSON.stringify(options[key])); | ||
} | ||
else { | ||
formData.append(key, options[key]); | ||
} | ||
} | ||
} | ||
} | ||
return formData; | ||
} | ||
async callApi(method, options, abortController) { | ||
@@ -83,0 +94,0 @@ const url = `${this.baseURL}/bot${this.botToken}${this.testEnvironment ? '/test' : ''}/${method}`; |
@@ -9,5 +9,5 @@ import { InputFile, MessageEntity, ParseMode } from './'; | ||
caption_entities?: MessageEntity[]; | ||
duration: number; | ||
duration?: number; | ||
performer?: string; | ||
title?: string; | ||
}; |
{ | ||
"type": "commonjs", | ||
"name": "typescript-telegram-bot-api", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"description": "Telegram Bot API wrapper for Node.js written in TypeScript", | ||
@@ -6,0 +6,0 @@ "repository": "github:Borodin/typescript-telegram-bot-api", |
Sorry, the diff of this file is too big to display
235519
5561