Skip to content

Commit

Permalink
fixed formdata breaking functions when a boolish value is added, adde…
Browse files Browse the repository at this point in the history
…d a note to find a proper solution later
  • Loading branch information
naseif committed Mar 3, 2022
1 parent 7fc4989 commit 83c9812
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/structure/TelegramAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from "../types";

import FormData from "form-data";
import { ReadStream } from "node:fs";

export class TelegramAPI {
/**
Expand Down Expand Up @@ -481,7 +482,7 @@ export class TelegramAPI {
*/
async sendPhoto(
chat_id: string | number,
photo: Buffer | string,
photo: ReadStream | string,
options?: sendPhotoOptions
): Promise<IMessage> {
let params = {};
Expand All @@ -493,7 +494,7 @@ export class TelegramAPI {
form.append("photo", photo);
if (options) {
for (const [key, value] of Object.entries(options)) {
form.append(key, value);
form.append(key, String(value));
}
}
postOptions = {
Expand Down Expand Up @@ -536,7 +537,7 @@ export class TelegramAPI {
*/
async sendAudio(
chat_id: string | number,
audio: Buffer | string,
audio: ReadStream | string,
options?: sendAudioOptions
): Promise<IMessage> {
let params = {};
Expand All @@ -546,9 +547,10 @@ export class TelegramAPI {
if (this.isReadableStream(audio)) {
form.append("chat_id", chat_id);
form.append("audio", audio);
// TODO: When one of the options has a boolean value, FromData throws an exception for some reason, need to investigate this asap since its breaking the function
if (options) {
for (const [key, value] of Object.entries(options)) {
form.append(key, value);
form.append(key, String(value));
}
}
postOptions = {
Expand Down Expand Up @@ -592,7 +594,7 @@ export class TelegramAPI {

async sendVideo(
chat_id: string,
video: Buffer | string,
video: ReadStream | string,
options?: sendVideoOptions
): Promise<IMessage> {
let params = {};
Expand All @@ -604,7 +606,7 @@ export class TelegramAPI {
form.append("video", video);
if (options) {
for (const [key, value] of Object.entries(options)) {
form.append(key, value);
form.append(key, String(value));
}
}
postOptions = {
Expand Down Expand Up @@ -649,7 +651,7 @@ export class TelegramAPI {

async sendDocument(
chat_id: number | string,
document: Buffer | string,
document: ReadStream | string,
options?: sendDocumentOptions
): Promise<IMessage> {
let params = {};
Expand All @@ -661,7 +663,7 @@ export class TelegramAPI {
form.append("document", document);
if (options) {
for (const [key, value] of Object.entries(options)) {
form.append(key, value);
form.append(key, String(value));
}
}
postOptions = {
Expand Down Expand Up @@ -704,7 +706,7 @@ export class TelegramAPI {

async sendAnimation(
chat_id: string | number,
animation: Buffer | string,
animation: ReadStream | string,
options?: sendAnimationOptions
) {
let params = {};
Expand All @@ -716,7 +718,7 @@ export class TelegramAPI {
form.append("animation", animation);
if (options) {
for (const [key, value] of Object.entries(options)) {
form.append(key, value);
form.append(key, String(value));
}
}
postOptions = {
Expand Down Expand Up @@ -759,7 +761,7 @@ export class TelegramAPI {
*/
async sendVoice(
chat_id: string | number,
voice: Buffer | string,
voice: ReadStream | string,
options?: sendVoiceOptions
) {
let params = {};
Expand All @@ -771,7 +773,7 @@ export class TelegramAPI {
form.append("voice", voice);
if (options) {
for (const [key, value] of Object.entries(options)) {
form.append(key, value);
form.append(key, String(value));
}
}
postOptions = {
Expand Down Expand Up @@ -814,7 +816,7 @@ export class TelegramAPI {
*/
async sendVideoNote(
chat_id: string | number,
videoNote: Buffer | string,
videoNote: ReadStream | string,
options?: sendVideoNoteOptions
): Promise<IMessage> {
let params = {};
Expand All @@ -826,7 +828,7 @@ export class TelegramAPI {
form.append("video_note", videoNote);
if (options) {
for (const [key, value] of Object.entries(options)) {
form.append(key, value);
form.append(key, String(value));
}
}
postOptions = {
Expand Down

0 comments on commit 83c9812

Please sign in to comment.