Skip to content

Commit 05a69cf

Browse files
authored
feat: message.react (#21)
* feat: message.react * fix: other type * fix: other type again
1 parent eb0370e commit 05a69cf

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/data/message.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
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";
28
import { type Other as O, type Ret } from "../plugin.ts";
39
import { type InlineMessageXFragment } from "./inline-message.ts";
410
type Other<M extends keyof RawApi, K extends string = never> = O<
@@ -54,6 +60,24 @@ export interface MessageXFragment extends InlineMessageXFragment {
5460
*/
5561
delete(signal?: AbortSignal): Ret<"deleteMessage">;
5662

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+
5781
/**
5882
* 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.
5983
*
@@ -155,6 +179,20 @@ export function installMessageMethods(api: RawApi, message: Message) {
155179
},
156180
signal,
157181
),
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),
158196
getCustomEmojiStickers: async (signal) => {
159197
const entities = message.entities ?? message.caption_entities;
160198
if (entities === undefined || entities.length === 0) return [];

0 commit comments

Comments
 (0)