|
1 |
| -import { type Message, type MessageEntity, type RawApi } from "../deps.deno.ts"; |
| 1 | +import { |
| 2 | + type Message, |
| 3 | + type MessageEntity, |
| 4 | + type RawApi, |
| 5 | + type ReactionType, |
| 6 | + type ReactionTypeEmoji, |
| 7 | +} from "../deps.deno.ts"; |
2 | 8 | import { type Other as O, type Ret } from "../plugin.ts";
|
3 | 9 | import { type InlineMessageXFragment } from "./inline-message.ts";
|
4 | 10 | type Other<M extends keyof RawApi, K extends string = never> = O<
|
@@ -54,6 +60,24 @@ export interface MessageXFragment extends InlineMessageXFragment {
|
54 | 60 | */
|
55 | 61 | delete(signal?: AbortSignal): Ret<"deleteMessage">;
|
56 | 62 |
|
| 63 | + /** |
| 64 | + * 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. |
| 65 | + * |
| 66 | + * @param reaction New list of reaction types to set on the message |
| 67 | + * @param other Optional remaining parameters, confer the official reference below |
| 68 | + * @param signal Optional `AbortSignal` to cancel the request |
| 69 | + * |
| 70 | + * **Official reference:** https://core.telegram.org/bots/api#setmessagereaction |
| 71 | + */ |
| 72 | + react( |
| 73 | + reaction: |
| 74 | + | ReactionTypeEmoji["emoji"] |
| 75 | + | ReactionType |
| 76 | + | Array<ReactionTypeEmoji["emoji"] | ReactionType>, |
| 77 | + other?: Other<"setMessageReaction", "reaction">, |
| 78 | + signal?: AbortSignal, |
| 79 | + ): Ret<"setMessageReaction">; |
| 80 | + |
57 | 81 | /**
|
58 | 82 | * 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.
|
59 | 83 | *
|
@@ -155,6 +179,20 @@ export function installMessageMethods(api: RawApi, message: Message) {
|
155 | 179 | },
|
156 | 180 | signal,
|
157 | 181 | ),
|
| 182 | + react: (reaction, other, signal) => |
| 183 | + api.setMessageReaction({ |
| 184 | + chat_id: message.chat.id, |
| 185 | + message_id: message.message_id, |
| 186 | + reaction: typeof reaction === "string" |
| 187 | + ? [{ type: "emoji", emoji: reaction }] |
| 188 | + : (Array.isArray(reaction) ? reaction : [reaction]) |
| 189 | + .map((emoji) => |
| 190 | + typeof emoji === "string" |
| 191 | + ? { type: "emoji", emoji } |
| 192 | + : emoji |
| 193 | + ), |
| 194 | + ...other, |
| 195 | + }, signal), |
158 | 196 | getCustomEmojiStickers: async (signal) => {
|
159 | 197 | const entities = message.entities ?? message.caption_entities;
|
160 | 198 | if (entities === undefined || entities.length === 0) return [];
|
|
0 commit comments