@grammyjs/hydrate
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -1,2 +0,2 @@ | ||
import { type InlineKeyboardMarkup, type InputFile, type InputFileProxy, type RawApi, type SentWebAppMessage } from "../deps.node.js"; | ||
import { type InlineKeyboardMarkup, type InputMedia, type RawApi, type SentWebAppMessage } from "../deps.node.js"; | ||
import { Other as O, Ret } from "../plugin.js"; | ||
@@ -63,3 +63,3 @@ type Other<M extends keyof RawApi, K extends string = never> = O<M, K | "chat_id" | "message_id">; | ||
*/ | ||
editMedia(media: InputFileProxy<InputFile>["InputMedia"], other?: Other<"editMessageMedia", "inline_message_id" | "media">, signal?: AbortSignal): Ret<"editMessageMedia">; | ||
editMedia(media: InputMedia, other?: Other<"editMessageMedia", "inline_message_id" | "media">, signal?: AbortSignal): Ret<"editMessageMedia">; | ||
} | ||
@@ -66,0 +66,0 @@ export type InlineMessageX = InlineMessageXFragment & SentWebAppMessage; |
@@ -1,2 +0,2 @@ | ||
import { type Message, type RawApi } from "../deps.node.js"; | ||
import { type Message, type RawApi, type ReactionType, type ReactionTypeEmoji } from "../deps.node.js"; | ||
import { type Other as O, type Ret } from "../plugin.js"; | ||
@@ -43,2 +43,12 @@ import { type InlineMessageXFragment } from "./inline-message.js"; | ||
/** | ||
* Message-aware alias for `api.setMessageReaction`. Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. In albums, bots must react to the first message. Returns True on success. | ||
* | ||
* @param reaction New list of reaction types to set on the message | ||
* @param other Optional remaining parameters, confer the official reference below | ||
* @param signal Optional `AbortSignal` to cancel the request | ||
* | ||
* **Official reference:** https://core.telegram.org/bots/api#setmessagereaction | ||
*/ | ||
react(reaction: ReactionTypeEmoji["emoji"] | ReactionType | Array<ReactionTypeEmoji["emoji"] | ReactionType>, other?: Other<"setMessageReaction", "reaction">, signal?: AbortSignal): Ret<"setMessageReaction">; | ||
/** | ||
* Message-aware alias for `api.getCustomEmojiStickers`. Use this method to get information about emoji stickers by their identifiers. Returns an Array of Sticker on success. | ||
@@ -45,0 +55,0 @@ * |
@@ -57,2 +57,13 @@ "use strict"; | ||
}, signal), | ||
react: (reaction, other, signal) => api.setMessageReaction({ | ||
chat_id: message.chat.id, | ||
message_id: message.message_id, | ||
reaction: typeof reaction === "string" | ||
? [{ type: "emoji", emoji: reaction }] | ||
: (Array.isArray(reaction) ? reaction : [reaction]) | ||
.map((emoji) => typeof emoji === "string" | ||
? { type: "emoji", emoji } | ||
: emoji), | ||
...other, | ||
}, signal), | ||
getCustomEmojiStickers: async (signal) => { | ||
@@ -59,0 +70,0 @@ var _a; |
export { Api, ApiCallFn, Context, GrammyError, InputFile, RawApi, Transformer, } from "grammy"; | ||
export * from "@grammyjs/types"; | ||
export * from "grammy/types"; |
@@ -23,2 +23,2 @@ "use strict"; | ||
Object.defineProperty(exports, "InputFile", { enumerable: true, get: function () { return grammy_1.InputFile; } }); | ||
__exportStar(require("@grammyjs/types"), exports); | ||
__exportStar(require("grammy/types"), exports); |
import { type CallbackQueryX } from "./data/callback-query.js"; | ||
import { type ChatJoinRequestX } from "./data/chat-join-request.js"; | ||
import { type ChatX } from "./data/chat.js"; | ||
import { type InlineQueryX } from "./data/inline-query.js"; | ||
@@ -7,4 +8,5 @@ import { type MessageX } from "./data/message.js"; | ||
import { type ShippingQueryX } from "./data/shipping-query.js"; | ||
import { type UpdateX } from "./data/update.js"; | ||
import { type Api, type Context, type InputFile, type InputFileProxy, type RawApi, type Transformer, type Update } from "./deps.node.js"; | ||
import { UpdateX } from "./data/update.js"; | ||
import { type ChatMemberX } from "./data/user.js"; | ||
import { type Api, type Context, type Opts, type RawApi, type Transformer, type Update } from "./deps.node.js"; | ||
/** | ||
@@ -50,2 +52,4 @@ * Transformative API Flavor that adds file handling utilities to the supplied | ||
setGameScore: MessageX | true; | ||
getChat: ChatX; | ||
getChatMember: ChatMemberX; | ||
} | ||
@@ -68,3 +72,2 @@ /** | ||
export type Other<M extends keyof RawApi, K extends string = never> = Omit<Opts<M>, K>; | ||
export type Opts<M extends keyof RawApi> = InputFileProxy<InputFile>["Opts"][M]; | ||
export type Ret<M extends keyof RawApi> = ReturnType<RawApi[M]>; | ||
@@ -98,2 +101,5 @@ type ObjectAssign<DestType, SourceType> = { | ||
replyWithGame: Extend<C["replyWithGame"], X["sendGame"]>; | ||
getChatMember: Extend<C["getChatMember"], X["getChatMember"]>; | ||
getChat: Extend<C["getChat"], X["getChat"]>; | ||
getAuthor: Extend<C["getAuthor"], X["getChatMember"]>; | ||
update: UpdateX; | ||
@@ -100,0 +106,0 @@ message: (MessageX & Update.NonChannel) | undefined; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.hydrateApi = exports.hydrateContext = exports.hydrate = void 0; | ||
const chat_js_1 = require("./data/chat.js"); | ||
const inline_message_js_1 = require("./data/inline-message.js"); | ||
const message_js_1 = require("./data/message.js"); | ||
const update_js_1 = require("./data/update.js"); | ||
const user_js_1 = require("./data/user.js"); | ||
const deps_node_js_1 = require("./deps.node.js"); | ||
@@ -46,2 +48,8 @@ /** | ||
} | ||
else if (isChatMember(res.result) && hasChatId(payload)) { | ||
(0, user_js_1.installUserMethods)(toApi(prev), res.result.user, payload.chat_id); | ||
} | ||
else if (isChat(res.result)) { | ||
(0, chat_js_1.installChatMethods)(toApi(prev), res.result); | ||
} | ||
// TODO: hydrate other method call results | ||
@@ -65,20 +73,22 @@ } | ||
} | ||
// TODO: add support for the following methods of these objects | ||
// === USERS | ||
// - get user profile photos | ||
// - ban | ||
// - unban | ||
// - restrict | ||
// - promote | ||
// - set custom title | ||
// - get (private) | ||
// - get in chat (groups) | ||
// === CHATS | ||
// - set permissions | ||
// - get | ||
// - get admins | ||
// - get private chat, get group chat, etc with narrowed return types | ||
// - etc | ||
// - all send message methods? | ||
// - just everything that has a chat_id? | ||
function isChatMember(obj) { | ||
return (typeof obj === "object" && | ||
obj !== null && | ||
"status" in obj && | ||
"user" in obj); | ||
} | ||
function isChat(obj) { | ||
return (typeof obj === "object" && | ||
obj !== null && | ||
"id" in obj && | ||
"type" in obj && | ||
typeof obj.type === "string" && | ||
["private", "group", "supergroup", "channel"].includes(obj.type)); | ||
} | ||
function hasChatId(obj) { | ||
return (typeof obj === "object" && | ||
obj !== null && | ||
"chat_id" in obj && | ||
typeof obj.chat_id === "number"); | ||
} | ||
function toApi(connector) { | ||
@@ -85,0 +95,0 @@ return new Proxy({}, { |
{ | ||
"name": "@grammyjs/hydrate", | ||
"description": "Hydration plugin for grammY", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"author": "KnorpelSenf", | ||
@@ -30,3 +30,2 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@grammyjs/types": "^2.11.1", | ||
"@types/node": "^12.20.55", | ||
@@ -33,0 +32,0 @@ "deno2node": "^1.7.1" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56112
2
33
959