Send an image link to telegram without display image url
Asked Answered
P

8

16

I need send an image url to telegram without display image url and hidden url. I see a telegram bot and it's do it very well and send long message with image I'm attach this bot result image see it. Now how can do it in my custom bot? It's possible hidden url with MARKDOWN style or any way? I want hidden image url in my text but telegram display my image. see my sample attach image. thank you

enter image description here

Pringle answered 19/9, 2016 at 22:39 Comment(0)
G
9

Most of them use the dot (or some things like this character) for link description and you thought there is no link.

You can type the following line and select custom markdown:

@bold [.](http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg)

If you want to add text to your link, you need to create a bot and use this approach in the bot.

Edit:

For sending hyperlink with the bot api you can simply send html markup and using parse_mode. See telegram documents:

To use this mode, pass HTML in the parse_mode field when using sendMessage. The following tags are currently supported:

<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<a href="http://www.example.com/">inline URL</a>
<a href="tg://user?id=123456789">inline mention of a user</a>
<code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre>

sample:

<a href="http://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg"></a>
Glorious answered 20/9, 2016 at 19:11 Comment(3)
Thank you dear Naser Yousefi I'm using dot before but I see a bot without using dot or any character and display image with long message I don't know how do itPringle
You can use a persian bot in telegram named @AxNegarBot. simply send an image to it and then reply that image and send your long text.Glorious
Thank you Dear Naser Yousefi I'm see Persian bot it's very good I want created my custom bot and do it I need this code. can you help me?Pringle
T
8

According to the Telegram API, it seems if you set disable_web_page_preview to true, you should get the result you want.

The final message should look something like this:

{
    chat_id: 1235,
    message: "http://your/url",
    disable_web_page_preview: true,
}

EDIT: It seems I misunderstood the question, and you actually want the image to appear by itself rather than the url by itself.

Again, as per the Telegram API you can send an image directly. But as far as I can tell, you can't use a URL to do it. You would have to upload the photo from your telegram server directly. You could use the caption property to send text with it.

Here is an example of how you might be able do this in python. You will need to tweak this to whichever language you are using, but the concept is the same.

import requests

response = requests.post(
    "https://your.bot.url.com/sendPhoto",
    data={
        "chat_id": 1234,
        "caption": "Your extra text here"
    }
    files={
        "photo": (
            "image_name.jpg",
            "contents of image",
            "image/jpg",
            {},
        )
    }
)

The caption property has a limit of 200 characters, so if you want to send more characters then that, you'll have to send two messages.

You can always ask Telegram to add this type of functionality in the future

Thorite answered 19/9, 2016 at 23:26 Comment(7)
thank you but my problem is not disable_web_page_preview I need hidden url when send for example i.stack.imgur.com/BWjTS.png to telegram only display image not display urlPringle
Right, so you want only the image to appear, and not any text?Thorite
I need send long text with image if I can send image without display image url I can send my text and image. It's my demo result: i.stack.imgur.com/BWjTS.pngPringle
image caption is very limited I can send image and caption with php but I need another program If you see this bot telegram.me/AxNegarBot it's send image with 4000 character I need it in my program this bot hidden image url but display imagePringle
In that case I suggest you send two messages - the image with no caption, and a normal message just before/after it. You cannot send them at the same time.Thorite
Thank you I want to send one message, such as sample botPringle
The sample bot seems to use a caption. If you can't use a caption because of its limited length, you have to send two messages.Thorite
I
7

The answer is zero-width non-joiner (ZWNJ) character. ZWNJ is encoded in Unicode as U+200C ZERO WIDTH NON-JOINER (HTML &#8204; , &zwnj;).

HTML mode:

<a href="https://example.com">&#8204;</a>

MARKDOWN mode:

[‌‌](https://example.com)

Update 2021:

The answer is still working but telegram doesn't let you send an empty text message that include only this character anymore, so you have to add at least one character in the whole text message. In addition you can also use the character Unicode Character 'WORD JOINER' (U+2060) instead.

Intertwist answered 17/10, 2017 at 0:37 Comment(3)
this is the correct answer. covers both html and markdown modesHeuser
I'm trying to use it in PHP, but is not working. The POST return with 'bad request'.Garrotte
There is a hidden character in between brackets, you can copy and use it.Intertwist
T
6

You can use &#160; character as hidden character.

Truscott answered 22/9, 2016 at 15:58 Comment(1)
This actually has the effect of rendering a space (it's the same as writing &nbsp), but it worksClaud
C
1

This might help:

enter image description here

It works for both:

  • web links
  • telegram links
Chaps answered 20/10, 2021 at 7:54 Comment(0)
H
0
import requests
def telegram(channel,bot,text,img):
    if(text==""):text="Refer - "
    r = requests.get('https://api.telegram.org/bot'+bot+'/sendMessage?chat_id=@'+channel+'&parse_mode=markdown&text='+"[​​​​​​​​​​​]("+img+")"+text)

Use the above function. It will work perfectly. In case, there is no text and only image, it should break. So it will show a "." (dot) in those cases.

Now use the function -

telegram(your_channel_name,your_token_here,description,image_url)
Hardie answered 17/11, 2019 at 6:59 Comment(0)
C
0

To correctly send an image hosted on a website without showing any reference link, you must use the "html" parsing mode.

And in the content to send, for example, something like this (Python mode):

# We take the html address of the image.
image_address = 'https://picsum.photos/100.jpg'

# The unicode character to prevent the words from 
# being separated, in this case, we take advantage 
# of it so that the Telegram API accepts it and 
# incidentally so that it does not take up space 
# when including text in the message.
word_joiner = '&#8288' 

# This would be the final pattern.
html_pattern = f'<a href="{image_address}">{word_joiner}</a>' 
Cobbie answered 4/8, 2021 at 14:40 Comment(0)
O
-1

With HTML parse mode. Keep empty space between the opening and closing tag.

<a href="https://t.me/"> </a>
Oscillator answered 2/8, 2019 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.