Reputation: 329
I'm on a channel that sends messages that contains a text, with a link (that link has not an image) and an image (tip product from amazon):
I tried with this code and it's similar:
bot.telegram.sendMessage('mychannel', `Hello https:/path/to/image.jpg`)
And it works it similar, but it remains the link. SO how can i put that way with image preview but not the link?
Thank you
Upvotes: 1
Views: 2018
Reputation: 7538
One workaround(trick) would be to insert the link but use an empty character unicode (like from https://emptycharacter.com/)
Here is an example (I inserted the photo URL with an empty character)
some sample code to get you started:
const Telegraf = require("telegraf");
const bot = new Telegraf(" ... ");
const CHAT_ID = ... ;
function getHiddenLink(url, parse_mode = "markdown") {
const emptyChar = ""; // copied and pasted the char from https://emptycharacter.com/
switch (parse_mode) {
case "markdown":
return `[${emptyChar}](${url})`;
case "HTML":
return `<a href="${url}">${emptyChar}</a>`;
default:
throw new Error("invalid parse_mode");
}
}
// Option 1: sending with MARKDOWN syntax
bot.telegram.sendMessage(
CHAT_ID,
`
some test text in markdown
${getHiddenLink("https://i.sstatic.net/TPKR5.png", "markdown")}
`,
{
parse_mode: "markdown",
}
);
// Another option: sending with HTML syntax
bot.telegram.sendMessage(
CHAT_ID,
`
some test text in HTML
${getHiddenLink("https://i.sstatic.net/TPKR5.png", "HTML")}
`,
{
parse_mode: "HTML",
}
);
Here we just create a new function getHiddenLink()
that accepts the URL and parse_mode (HTML or markdown) and just craft a new URL representation with the empty character as the link-text and return it.
Upvotes: 1
Reputation: 34
There is no way to send a preview without a link. You can try to have some by your own telegram account and you will see it is impossible. Instead of preview, add some caption to photos.
Upvotes: 0