Public
Back
Version 59
3/20/2023
export async function bebopBotWebhook(
req: express.Request,
res: express.Response
) {
// const requestSecretToken = req.header("x-telegram-bot-api-secret-token");
// if (requestSecretToken !== @me.bebopBotSecretToken) {
// return res.status(403).send("Access denied");
// }
return res.send("breakpoint");
const { channel_post: channelPost } = req.body;
if (!channelPost) {
res.send("ok");
return;
}
const {
text,
entities: textEntities,
caption,
caption_entities: captionEntities,
} = channelPost;
const entities = textEntities || captionEntities;
let textToSend = text || caption;
let accumOffset = 0;
for (const entry of entities) {
if (entry.type === "text_link") {
const { offset, length, url } = entry;
const entryStart = offset + accumOffset;
const mdUrl = getMarkdownLink(
textToSend.substring(entryStart, entryStart + length),
url
);
textToSend =
textToSend.substring(0, entryStart) +
mdUrl +
textToSend.substring(entryStart + length);
accumOffset = mdUrl.length - length;
Updated: October 23, 2023