javascript 如何从网站向 Telegram APP 发送消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31092657/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:16:15  来源:igfitidea点击:

How to send message from Website To Telegram APP

javascripthtmlmobilesendmessagetelegram

提问by iKamy

I have a share button in my website and I want to send a specific message to Telegram APP contacts (when I open website in Mobile)

我的网站上有一个分享按钮,我想向 Telegram APP 联系人发送特定消息(当我在移动设备中打开网站时)

The Problem is I didnt find the complete code and it just open the APP in the mobile

问题是我没有找到完整的代码,它只是在手机中打开APP

my code is :

我的代码是:

<a href="tg://" id="telegram_share" class="mobileShare" title="inviteFriends" alt="telegram_share"></a>

as you see I didnt find proper command for sending message in href property

如您所见,我没有找到在 href 属性中发送消息的正确命令

for example I found something simillar for adding sticker like :

例如,我发现了一些类似的添加贴纸的东西,例如:

<a class="tgme_action_button" href="tg://addstickers?set=Saber2">Add Stickers</a>

回答by iKamy

iT's called URI Scheme Hope this one save someone else's time :)

iT 叫做 URI Scheme 希望这个可以节省别人的时间 :)

<a href="tg://msg?text=your MsG!" id="telegram_share" class="mobileShare" title="inviteFriends" alt="telegram_share"></a>

right Now it only works on IOS

现在它只适用于 IOS

回答by DavidTaubmann

USE THE API

使用 API

Once you've set up a username, you can give people a t.me/usernamelink. Opening that link on their phone will automatically fire up their Telegram app and open a chat with you. You can share username links with friends, write them on business cards or put them up on your website.

设置用户名后,您可以向人们提供t.me/username链接。在他们的手机上打开该链接将自动启动他们的 Telegram 应用程序并与您开始聊天。您可以与朋友分享用户名链接,将它们写在名片上或放在您的网站上。

This way people can contact you on Telegram without knowing your phone number.

这样人们就可以在不知道您的电话号码的情况下通过 Telegram 与您联系。

That is currently the best way to link to someone's Telegram, and is stated officially in here: https://telegram.org/faq/en#q-how-does-t-me-work

这是目前链接到某人 Telegram 的最佳方式,并在此处正式说明:https: //telegram.org/faq/en#q-how-does-t-me-work

This method redirects to:

此方法重定向到:

tg://resolve?domain=username

tg://resolve?domain=username

If you want to send a message, there's no official information about it, so you would need to do it using URI scheme as mentioned in the question, using this structure (which doesn't seem to allow specifying to whom the message will be sent):

如果你想发送一条消息,没有关于它的官方信息,所以你需要使用问题中提到的 URI 方案,使用这个结构(它似乎不允许指定消息将发送给谁) ):

tg://msg?text=yourMsG

tg://msg?text=yourMsG

It seems we can't mix both.

似乎我们不能两者兼而有之。