UNPKG

tgsnake

Version:

Telegram MTProto framework for nodejs.

116 lines (115 loc) 5.13 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.sendMessage = sendMessage; const platform_node_js_1 = require("../../platform.node.js"); const Utilities_js_1 = require("../../Utilities.js"); const ReplyMarkup = __importStar(require("../../TL/Messages/ReplyMarkup.js")); const index_js_1 = require("../../TL/Messages/index.js"); const index_js_2 = require("../../TL/Advanced/index.js"); const Logger_js_1 = require("../../Context/Logger.js"); async function sendMessage(client, chatId, text, more = {}) { Logger_js_1.Logger.debug(`exec: send_message chat ${typeof chatId} (${chatId}) text_length ${text.length} ${(0, Utilities_js_1.parseArgObjAsStr)(more)}`); var { disableWebPagePreview, disableNotification, replyToMessageId, replyToStoryId, replyParameters, messageThreadId, scheduleDate, sendAsChannel, protectContent, replyMarkup, entities, parseMode, invertMedia, } = more; const peer = await client._client.resolvePeer(chatId); if (parseMode && !entities) { const [t, e] = await platform_node_js_1.Parser.parse(text, parseMode); entities = e; text = t; } const res = await client._client.invoke(new platform_node_js_1.Raw.messages.SendMessage({ noWebpage: disableWebPagePreview, silent: disableNotification, clearDraft: true, noforwards: protectContent, peer: peer, replyTo: replyToMessageId || replyParameters ? await (0, Utilities_js_1.buildReply)(client, replyParameters ? replyParameters : { messageId: replyToMessageId }, messageThreadId) : replyToStoryId ? new platform_node_js_1.Raw.InputReplyToStory({ peer: peer, storyId: replyToStoryId, }) : undefined, message: text, randomId: client._rndMsgId.getMsgId(), replyMarkup: replyMarkup ? await ReplyMarkup.buildReplyMarkup(replyMarkup, client) : undefined, entities: entities ? await platform_node_js_1.Parser.toRaw(client._client, entities) : undefined, scheduleDate: scheduleDate ? scheduleDate.getTime() / 1000 : undefined, sendAs: sendAsChannel ? await client._client.resolvePeer(sendAsChannel) : undefined, updateStickersetsOrder: true, invertMedia: invertMedia, })); if (res instanceof platform_node_js_1.Raw.UpdateShortSentMessage) { let peerId = BigInt(0); let peerType = 'private'; if (peer instanceof platform_node_js_1.Raw.InputPeerUser) { peerId = peer.userId; } else if (peer instanceof platform_node_js_1.Raw.InputPeerChat) { peerId = BigInt(-peer.chatId); peerType = 'group'; } return new index_js_1.Message({ id: res.id, chat: new index_js_2.Chat({ id: peerId, type: peerType, accessHash: BigInt(0), }, client), date: new Date(res.date * 1000), empty: false, text, replyMarkup, entities, }, client); } if ('updates' in res) { for (const update of res.updates) { if (update instanceof platform_node_js_1.Raw.UpdateNewMessage || update instanceof platform_node_js_1.Raw.UpdateNewChannelMessage || update instanceof platform_node_js_1.Raw.UpdateNewScheduledMessage) { return await index_js_1.Message.parse(client, update.message, res.chats || [], res.users || []); } } } return new index_js_1.Message({ id: 'id' in res ? res.id : 0, outgoing: true, empty: true, }, client); }