UNPKG

tgram.js

Version:

Lightweight modern library for telegram bot. use Node.js

32 lines (30 loc) 1.61 kB
import { sendMessage } from "../messages/messages-send.js"; import { sendPhoto as sendPhotoMessage } from "../messages/messages-send-photo.js"; import { sendAudio } from "../messages/messages-send-audio.js"; import { sendVideo } from "../messages/messages-send-video.js"; import { sendSticker } from "../messages/messages-send-sticker.js"; import { sendDocument } from "../messages/messages-send-doc.js"; import { sendButton } from "../messages/button/button-send.js"; export function createContext(update, token, prefix) { const msg = update.message || {} const text = msg.text || "" const [cmd, ...args] = text.startsWith(prefix) ? text.slice(1).split(" ") : ["", []] return { update, jid: msg.chat?.id, message: msg, chat: msg.chat, from: msg.from, text, command: cmd?.toLowerCase(), args, textArgs: args.join(" "), reply: (text) => sendMessage(token, msg.chat?.id, text), sendPhoto: (photo, caption) => sendPhotoMessage(token, msg.chat?.id, photo, caption), sendAudio: (audioUrl, filename, caption) => sendAudio(token, msg.chat?.id, audioUrl, filename, caption), sendVideo: (videoUrl, caption) => sendVideo(token, msg.chat?.id, videoUrl, caption), sendSticker: (stickerUrl, filename) => sendSticker(token, msg.chat?.id, stickerUrl, filename), sendDocument: (document, filename, caption) => sendDocument(token, msg.chat?.id, document, filename, caption), sendButton: (text, buttons, options) => sendButton(token, msg.chat?.id, text, buttons, options) } }