|
@@ -412,13 +412,13 @@ export interface IterMessagesParams {
|
|
/** Offset date (messages previous to this date will be retrieved). Exclusive. */
|
|
/** Offset date (messages previous to this date will be retrieved). Exclusive. */
|
|
offsetDate?: DateLike;
|
|
offsetDate?: DateLike;
|
|
/** Offset message ID (only messages previous to the given ID will be retrieved). Exclusive. */
|
|
/** Offset message ID (only messages previous to the given ID will be retrieved). Exclusive. */
|
|
- offsetId?: number;
|
|
|
|
|
|
+ offsetId: number;
|
|
/** All the messages with a higher (newer) ID or equal to this will be excluded. */
|
|
/** All the messages with a higher (newer) ID or equal to this will be excluded. */
|
|
- maxId?: number;
|
|
|
|
|
|
+ maxId: number;
|
|
/** All the messages with a lower (older) ID or equal to this will be excluded. */
|
|
/** All the messages with a lower (older) ID or equal to this will be excluded. */
|
|
- minId?: number;
|
|
|
|
|
|
+ minId: number;
|
|
/** Additional message offset (all of the specified offsets + this offset = older messages). */
|
|
/** Additional message offset (all of the specified offsets + this offset = older messages). */
|
|
- addOffset?: number;
|
|
|
|
|
|
+ addOffset: number;
|
|
/** The string to be used as a search query. */
|
|
/** The string to be used as a search query. */
|
|
search?: string;
|
|
search?: string;
|
|
/** The filter to use when returning messages.<br/>
|
|
/** The filter to use when returning messages.<br/>
|
|
@@ -451,6 +451,27 @@ export interface IterMessagesParams {
|
|
* When using this parameter, the filter and search parameters have no effect, since Telegram's API doesn't support searching messages in replies.
|
|
* When using this parameter, the filter and search parameters have no effect, since Telegram's API doesn't support searching messages in replies.
|
|
*/
|
|
*/
|
|
replyTo?: number;
|
|
replyTo?: number;
|
|
|
|
+ /** If set to `true`, messages which are scheduled will be returned.
|
|
|
|
+ * All other parameters will be ignored for this, except `entity`.
|
|
|
|
+ */
|
|
|
|
+ scheduled: boolean;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const IterMessagesDefaults: IterMessagesParams = {
|
|
|
|
+ limit: undefined,
|
|
|
|
+ offsetDate: undefined,
|
|
|
|
+ offsetId: 0,
|
|
|
|
+ maxId: 0,
|
|
|
|
+ minId: 0,
|
|
|
|
+ addOffset: 0,
|
|
|
|
+ search: undefined,
|
|
|
|
+ filter: undefined,
|
|
|
|
+ fromUser: undefined,
|
|
|
|
+ waitTime: undefined,
|
|
|
|
+ ids: undefined,
|
|
|
|
+ reverse: false,
|
|
|
|
+ replyTo: undefined,
|
|
|
|
+ scheduled: false,
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -460,7 +481,7 @@ export interface SendMessageParams {
|
|
/** The message to be sent, or another message object to resend as a copy.<br/>
|
|
/** The message to be sent, or another message object to resend as a copy.<br/>
|
|
* The maximum length for a message is 35,000 bytes or 4,096 characters.<br/>
|
|
* The maximum length for a message is 35,000 bytes or 4,096 characters.<br/>
|
|
* Longer messages will not be sliced automatically, and you should slice them manually if the text to send is longer than said length. */
|
|
* Longer messages will not be sliced automatically, and you should slice them manually if the text to send is longer than said length. */
|
|
- message: MessageLike;
|
|
|
|
|
|
+ message?: MessageLike;
|
|
/** Whether to reply to a message or not. If an integer is provided, it should be the ID of the message that it should reply to. */
|
|
/** Whether to reply to a message or not. If an integer is provided, it should be the ID of the message that it should reply to. */
|
|
replyTo?: number | Api.Message;
|
|
replyTo?: number | Api.Message;
|
|
/** Optional attributes that override the inferred ones, like DocumentAttributeFilename and so on. */
|
|
/** Optional attributes that override the inferred ones, like DocumentAttributeFilename and so on. */
|
|
@@ -506,7 +527,7 @@ export interface SendMessageParams {
|
|
/** interface used for forwarding messages */
|
|
/** interface used for forwarding messages */
|
|
export interface ForwardMessagesParams {
|
|
export interface ForwardMessagesParams {
|
|
/** The message(s) to forward, or their integer IDs. */
|
|
/** The message(s) to forward, or their integer IDs. */
|
|
- messages: MessageIDLike[];
|
|
|
|
|
|
+ messages: MessageIDLike | MessageIDLike[];
|
|
/** If the given messages are integer IDs and not instances of the Message class, this must be specified in order for the forward to work.<br/> */
|
|
/** If the given messages are integer IDs and not instances of the Message class, this must be specified in order for the forward to work.<br/> */
|
|
fromPeer: EntityLike;
|
|
fromPeer: EntityLike;
|
|
/** Whether the message should notify people with sound or not.<br/>
|
|
/** Whether the message should notify people with sound or not.<br/>
|
|
@@ -550,22 +571,12 @@ export interface EditMessageParams {
|
|
export function iterMessages(
|
|
export function iterMessages(
|
|
client: TelegramClient,
|
|
client: TelegramClient,
|
|
entity: EntityLike | undefined,
|
|
entity: EntityLike | undefined,
|
|
- {
|
|
|
|
- limit,
|
|
|
|
- offsetDate,
|
|
|
|
- offsetId,
|
|
|
|
- maxId,
|
|
|
|
- minId,
|
|
|
|
- addOffset,
|
|
|
|
- search,
|
|
|
|
- filter,
|
|
|
|
- fromUser,
|
|
|
|
- waitTime,
|
|
|
|
- ids,
|
|
|
|
- reverse = false,
|
|
|
|
- replyTo,
|
|
|
|
- }: IterMessagesParams
|
|
|
|
|
|
+ options: Partial<IterMessagesParams>
|
|
) {
|
|
) {
|
|
|
|
+ const {
|
|
|
|
+ limit, offsetDate, offsetId, maxId, minId, addOffset, search,
|
|
|
|
+ filter, fromUser, waitTime, ids, reverse, replyTo,
|
|
|
|
+ } = { ...IterMessagesDefaults, ...options };
|
|
if (ids) {
|
|
if (ids) {
|
|
let idsArray;
|
|
let idsArray;
|
|
if (!isArrayLike(ids)) {
|
|
if (!isArrayLike(ids)) {
|
|
@@ -588,7 +599,7 @@ export function iterMessages(
|
|
}
|
|
}
|
|
return new _MessagesIter(
|
|
return new _MessagesIter(
|
|
client,
|
|
client,
|
|
- limit || 1,
|
|
|
|
|
|
+ limit,
|
|
{
|
|
{
|
|
waitTime: waitTime,
|
|
waitTime: waitTime,
|
|
reverse: reverse,
|
|
reverse: reverse,
|
|
@@ -612,7 +623,7 @@ export function iterMessages(
|
|
export async function getMessages(
|
|
export async function getMessages(
|
|
client: TelegramClient,
|
|
client: TelegramClient,
|
|
entity: EntityLike | undefined,
|
|
entity: EntityLike | undefined,
|
|
- params: IterMessagesParams
|
|
|
|
|
|
+ params: Partial<IterMessagesParams>
|
|
): Promise<TotalList<Api.Message>> {
|
|
): Promise<TotalList<Api.Message>> {
|
|
if (Object.keys(params).length == 1 && params.limit === undefined) {
|
|
if (Object.keys(params).length == 1 && params.limit === undefined) {
|
|
if (params.minId === undefined && params.maxId === undefined) {
|
|
if (params.minId === undefined && params.maxId === undefined) {
|
|
@@ -637,7 +648,11 @@ export async function getMessages(
|
|
/** @hidden */
|
|
/** @hidden */
|
|
export async function sendMessage(
|
|
export async function sendMessage(
|
|
client: TelegramClient,
|
|
client: TelegramClient,
|
|
|
|
+ /** To who will it be sent. */
|
|
entity: EntityLike,
|
|
entity: EntityLike,
|
|
|
|
+ /** The message to be sent, or another message object to resend as a copy.<br/>
|
|
|
|
+ * The maximum length for a message is 35,000 bytes or 4,096 characters.<br/>
|
|
|
|
+ * Longer messages will not be sliced automatically, and you should slice them manually if the text to send is longer than said length. */
|
|
{
|
|
{
|
|
message,
|
|
message,
|
|
replyTo,
|
|
replyTo,
|
|
@@ -653,7 +668,7 @@ export async function sendMessage(
|
|
silent,
|
|
silent,
|
|
supportStreaming,
|
|
supportStreaming,
|
|
schedule,
|
|
schedule,
|
|
- }: SendMessageParams
|
|
|
|
|
|
+ }: SendMessageParams = {}
|
|
) {
|
|
) {
|
|
if (file) {
|
|
if (file) {
|
|
return client.sendFile(entity, {
|
|
return client.sendFile(entity, {
|
|
@@ -678,7 +693,7 @@ export async function sendMessage(
|
|
}
|
|
}
|
|
entity = await client.getInputEntity(entity);
|
|
entity = await client.getInputEntity(entity);
|
|
let markup, request;
|
|
let markup, request;
|
|
- if (message instanceof Api.Message) {
|
|
|
|
|
|
+ if (message && message instanceof Api.Message) {
|
|
if (buttons == undefined) {
|
|
if (buttons == undefined) {
|
|
markup = message.replyMarkup;
|
|
markup = message.replyMarkup;
|
|
} else {
|
|
} else {
|
|
@@ -720,7 +735,7 @@ export async function sendMessage(
|
|
if (formattingEntities == undefined) {
|
|
if (formattingEntities == undefined) {
|
|
[message, formattingEntities] = await _parseMessageText(
|
|
[message, formattingEntities] = await _parseMessageText(
|
|
client,
|
|
client,
|
|
- message,
|
|
|
|
|
|
+ message || '',
|
|
parseMode
|
|
parseMode
|
|
);
|
|
);
|
|
}
|
|
}
|
|
@@ -766,6 +781,9 @@ export async function forwardMessages(
|
|
entity: EntityLike,
|
|
entity: EntityLike,
|
|
{ messages, fromPeer, silent, schedule }: ForwardMessagesParams
|
|
{ messages, fromPeer, silent, schedule }: ForwardMessagesParams
|
|
) {
|
|
) {
|
|
|
|
+ if (!isArrayLike(messages)) {
|
|
|
|
+ messages = [messages]
|
|
|
|
+ }
|
|
entity = await client.getInputEntity(entity);
|
|
entity = await client.getInputEntity(entity);
|
|
let fromPeerId: number | undefined;
|
|
let fromPeerId: number | undefined;
|
|
if (fromPeer) {
|
|
if (fromPeer) {
|