Last active
March 8, 2023 13:20
-
-
Save MKRhere/9a047f07ab7e65b35f5fa63f2db94304 to your computer and use it in GitHub Desktop.
Copy message contents in Telegraf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Composer } from "telegraf"; | |
import type { Update, Message } from "telegraf/types"; | |
function copyMsg( | |
ctx: Context<Update.MessageUpdate<Message.TextMessage>>, | |
content: Message & Update.NonChannel & Update.New, | |
) { | |
const tg = ctx.telegram; | |
const chat_id = ctx.chat.id; | |
if ("text" in content) | |
return tg.callApi("sendMessage", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
text: content.text, | |
entities: content.entities, | |
}); | |
else if ("contact" in content) | |
return tg.callApi("sendContact", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
phone_number: content.contact.phone_number, | |
first_name: content.contact.first_name, | |
last_name: content.contact.last_name, | |
}); | |
else if ("location" in content) | |
return tg.callApi("sendLocation", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
latitude: content.location.latitude, | |
longitude: content.location.longitude, | |
}); | |
else if ("animation" in content) | |
return tg.callApi("sendAnimation", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
animation: content.animation.file_id, | |
duration: content.animation.duration, | |
}); | |
else if ("voice" in content) | |
return tg.callApi("sendVoice", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
voice: content.voice.file_id, | |
duration: content.voice.duration, | |
caption: content.caption, | |
caption_entities: content.caption_entities, | |
}); | |
else if ("audio" in content) | |
return tg.callApi("sendAudio", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
audio: content.audio.file_id, | |
duration: content.audio.duration, | |
performer: content.audio.performer, | |
title: content.audio.title, | |
caption: content.caption, | |
caption_entities: content.caption_entities, | |
}); | |
else if ("video" in content) | |
return tg.callApi("sendVideo", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
video: content.video.file_id, | |
caption: content.caption, | |
caption_entities: content.caption_entities, | |
duration: content.video.duration, | |
width: content.video.width, | |
height: content.video.height, | |
}); | |
else if ("document" in content) | |
return tg.callApi("sendDocument", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
document: content.document.file_id, | |
caption: content.caption, | |
caption_entities: content.caption_entities, | |
}); | |
else if ("sticker" in content) | |
return tg.callApi("sendSticker", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
sticker: content.sticker.file_id, | |
}); | |
else if ("photo" in content) | |
return tg.callApi("sendPhoto", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
photo: content.photo.at(-1)!.file_id, | |
caption: content.caption, | |
caption_entities: content.caption_entities, | |
}); | |
else if ("video_note" in content) | |
return tg.callApi("sendVideoNote", { | |
chat_id, | |
reply_markup: content.reply_markup, | |
video_note: content.video_note.file_id, | |
length: content.video_note.length, | |
duration: content.video_note.duration, | |
}); | |
else if ("poll" in content) | |
return tg.callApi("sendPoll", { | |
chat_id, | |
question: content.poll.question, | |
type: content.poll.type, | |
is_anonymous: content.poll.is_anonymous, | |
allows_multiple_answers: content.poll.allows_multiple_answers, | |
correct_option_id: content.poll.correct_option_id, | |
options: content.poll.options.map(({ text }) => text), | |
}); | |
else return tg.sendMessage(chat_id, "Unsupported message"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment