47

I want to share a link via URL scheme for Telegram.

I have created this:

tg://msg?text = www.example.com?t=12

The link, opens telegram but nothing else happens.

I have used the same code for Viber, and it works:

viber://forward?text = www.example.com?t=12

And it opens a new message in Viber with this text:

www.example.com

In the other words, it cuts my URL.

Any ideas?

13 Answers 13

79

You can also use telegram.me share link which falls back to webogram if a telegram app is not installed on the device.

https://telegram.me/share/url?url=<URL>&text=<TEXT>

Sign up to request clarification or add additional context in comments.

5 Comments

can we open telegram to start chat with bot selected (not a number) i.e something like this tg://msg?text=HI there&to=@my_bot
@Qadir Hussain have you found any solution yet? contact added in phone contact, i use tg://msg?text=hi&to=+91XX then ios redirect to user chat screen, how cant i do in android?
@Maulikpatel this should help for android stackoverflow.com/questions/21627167/…
@QadirHussain it will redirect me to telegram but not particular user chat screen.
@Maulikpatel don't know about this in android
19

This works with me:

tg://msg?text=Mi_mensaje&to=+1555999

5 Comments

How to check isTelegram installed? in swift
can we open telegram to start chat with bot selected (not a number) i.e something like this tg://msg?text=Mi_mensaje&to=@my_bot
@QadirHussain to open telegram to start chat with bot use url like 'telegram.me/my_bot' . it redirects you to chat screen with that bot.
<a href = "tg://msg?text=Mi_mensaje&to=+1555999"><telegram</a> this is opening 'xdg' and after we should select contact. Is there any solution to open xdg and then contact and having sending message. thanks in advance.
I have the userId ( not a username ) like 854845663 How can I use it instead of a username?
16

You have the following options for a URL...

https://t.me/share/url?url={url}&text={text}
https://telegram.me/share/url?url={url}&text={text}
tg://msg_url?url={url}&text={text}

In case you want to confirm, here is the official API source: Core.Telegram.org: Widgets -> Sharing Button.

If you are interested in watching a project that keeps track of these URLs, then check us out!: https://github.com/bradvin/social-share-urls#telegramme

Social Share URLs

Comments

7

You can use the link telegram.me which will provide a preview page with an alert requesting to open the link in the application.

https://telegram.me/share/url?url=<URL>&text=<TEXT>

enter image description here

The second option is calling the application link directly:

tg://msg_url?url=<url>&text=<encoded-text>

I particularly prefer the second option, which also works on desktop applications.

Comments

5

For Telegram share:

Objective C:

if([UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tg://msg?text=test"]){
 [UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tg://msg?text=test"]
}else{
 //App not installed.
}

Swift 3.0:

let urlString = "tg://msg?text=test"
let tgUrl = URL.init(string:urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed)!)
if UIApplication.shared.canOpenURL(tgUrl!)
    {
        UIApplication.shared.openURL(tgUrl!)
    }else
    {
       //App not installed.
    }

If you have used canOpenURL, then need to add in info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
   <string>tg</string>
</array>

Comments

4
<a href = "https://telegram.me/share/url?url=<URL>&text=<TEXT>">Telegram</a>

with this we can open xdg of telegram and if we select contact , by default sending text will come in message field.

Comments

3

PHP

<a href="tg://msg?text=<?php echo rawurlencode($gotoURL); ?>">Link</a>


JavaScript

<script>TEXT="any text or url";</script>

<a onclick="window.location='tg://msg?text='+encodeURIComponent(TEXT);">Link</a>

Comments

1

Maybe you use localhost therefore it does not show share. try it in live host

Comments

1

You should stop using the protocol for the desktop applications because it does not work on the evolving web: it does not work on Web apps, ChromeOS, or some mobile devices.

Always use the NEW way: https://t.me because it will open the Telegram DESKTOP app in Windows\Linux\Mac IF THE USER WANTS\HAS it, otherwise it will open the WEB page\web app which is THE WAY.

  1. https://web.telegram.org/k
  2. https://web.telegram.org/z

Telegram has TWO web apps that have been building out for the past year!

Both are great, adding TONs of parity, and have different approaches.

Comments

0

To check if the Telegram is installed you can do the following (borrowed from the Whatsapp sharer module of ShareKit):

BOOL isTelegramInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tg://msg?text=test"]];

iOS checks if there's any app installed which can handle the tg:// scheme, which is Telegram.

Comments

0

Just tested, this way it works both opening telegram app or browser in case it's not installed:

let webURL = NSURL(string: "https://t.me/<YOUR ID>")!
UIApplication.shared.open(webURL as URL)

Comments

0

Your have two problems:

  1. On one hand you are using the wrong scheme for sharing URLs, the correct one is msg_url;
  2. On the other hand you are trying to share a URL with parameters. You need to encode your ? in order to make it work. The percent code is %3F
  3. Extra Tip: Also if you want it to be a link once shared you should include the HTTPS:// encoded of course.

Try this and you'll see it works fine: tg://msg_url?url=https%3A%2F%2Fwww.example.com%3Ft=12

Comments

0

If you want to open chat with bot or people, just write this simple code

<a href="https://t.me/targetedusername">

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.