Comparing version 0.0.3 to 0.0.4
@@ -1,12 +0,7 @@ | ||
import type { ApiMethods } from "@gramio/types"; | ||
import "reflect-metadata"; | ||
import { BotOptions } from "./types"; | ||
import { Updates } from "./updates"; | ||
export declare class Bot { | ||
readonly options: BotOptions; | ||
readonly api: ApiMethods; | ||
updates: Updates; | ||
private _callApi; | ||
constructor(token: string, options?: Omit<BotOptions, "token">); | ||
} | ||
export * from "./bot"; | ||
export * from "./apiErrors"; | ||
export * from "./types"; | ||
export * from "@gramio/contexts"; | ||
export * from "@gramio/files"; | ||
export * from "@gramio/keyboards"; | ||
export * from "@gramio/types"; |
@@ -13,8 +13,2 @@ "use strict"; | ||
})); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
@@ -24,50 +18,8 @@ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Bot = void 0; | ||
const files_1 = require("@gramio/files"); | ||
const form_data_encoder_1 = require("form-data-encoder"); | ||
const inspectable_1 = require("inspectable"); | ||
require("reflect-metadata"); | ||
const undici_1 = require("undici"); | ||
const apiErrors_1 = require("./apiErrors"); | ||
const updates_1 = require("./updates"); | ||
let Bot = class Bot { | ||
options = {}; | ||
api = new Proxy({}, { | ||
get: (_target, method) => (args) => this._callApi(method, args), | ||
}); | ||
updates = new updates_1.Updates(this); | ||
async _callApi(method, params = {}) { | ||
const url = `https://api.telegram.org/bot${this.options.token}/${method}`; | ||
const reqOptions = { | ||
method: "POST", | ||
duplex: "half", | ||
}; | ||
if ((0, files_1.isMediaUpload)(method, params)) { | ||
const formData = await (0, files_1.convertJsonToFormData)(method, params); | ||
const encoder = new form_data_encoder_1.FormDataEncoder(formData); | ||
reqOptions.body = encoder.encode(); | ||
reqOptions.headers = encoder.headers; | ||
} | ||
else { | ||
reqOptions.headers = { | ||
"Content-Type": "application/json", | ||
}; | ||
reqOptions.body = JSON.stringify(params); | ||
} | ||
const response = await (0, undici_1.fetch)(url, reqOptions); | ||
const data = (await response.json()); | ||
if (!data.ok) | ||
throw new apiErrors_1.APIError({ method, params }, data); | ||
return data.result; | ||
} | ||
constructor(token, options) { | ||
this.options = { ...options, token }; | ||
} | ||
}; | ||
exports.Bot = Bot; | ||
exports.Bot = Bot = __decorate([ | ||
(0, inspectable_1.Inspectable)({ | ||
serialize: () => ({}), | ||
}) | ||
], Bot); | ||
__exportStar(require("./bot"), exports); | ||
__exportStar(require("./apiErrors"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("@gramio/contexts"), exports); | ||
__exportStar(require("@gramio/files"), exports); | ||
__exportStar(require("@gramio/keyboards"), exports); | ||
__exportStar(require("@gramio/types"), exports); |
import { Context, contextsMappings } from "@gramio/contexts"; | ||
import type { TelegramUpdate } from "@gramio/types"; | ||
import { Bot } from "."; | ||
import { Bot } from "./bot"; | ||
import { THandler, UpdateNames } from "./types"; | ||
@@ -5,0 +5,0 @@ export declare class Updates { |
{ | ||
"name": "gramio", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "WIP", | ||
@@ -20,2 +20,4 @@ "main": "./dist/index.js", | ||
"@gramio/contexts": "^0.0.1", | ||
"@gramio/files": "^0.0.2", | ||
"@gramio/keyboards": "^0.1.6", | ||
"form-data-encoder": "^4.0.2", | ||
@@ -22,0 +24,0 @@ "inspectable": "^2.1.0", |
9767
12
247
8
+ Added@gramio/files@^0.0.2
+ Added@gramio/keyboards@^0.1.6
+ Added@gramio/files@0.0.2(transitive)
+ Added@gramio/keyboards@0.1.6(transitive)
+ Addedtypescript@5.7.3(transitive)