You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telegram WebApp不支持tel协议,求可行解决办法

解决Telegram WebApp中tel协议不支持的问题

Telegram WebApp的内置WebView出于限制,确实不直接支持tel:这类协议,包括Telegram.WebApp.openLink也无法绕过这个限制。可行的解决思路是让Telegram客户端本身处理拨号请求,而非在WebView内执行,具体有两种实现方案:

方案一:通过WebApp发送数据给Bot,由Bot回复拨号链接

利用Telegram.WebApp.sendData将号码传递给Bot,Bot收到后给用户发送包含tel:链接的消息,用户点击消息内的链接即可唤起拨号功能。

前端代码(WebApp内)

const dialPhone = () => {
  // 把拨号动作和号码通过sendData传给Bot
  Telegram.WebApp.sendData(JSON.stringify({ 
    action: 'initiate_call', 
    phone_number: '+14231231' 
  }));
}

Bot端处理(以Node.js的Telegraf库为例)

const { Telegraf } = require('telegraf');
const bot = new Telegraf('你的Bot Token');

// 监听WebApp发送的数据
bot.on('web_app_data', async (ctx) => {
  const payload = JSON.parse(ctx.webAppData.data);
  
  if (payload.action === 'initiate_call') {
    // 给用户回复带tel链接的消息
    await ctx.reply(
      `点击下方链接拨号:<a href="tel:${payload.phone_number}">${payload.phone_number}</a>`,
      { parse_mode: 'HTML' }
    );
  }
});

bot.launch();

方案二:通过后端中转触发Bot发送拨号链接

如果你的WebApp有后端服务,也可以通过前端请求后端,由后端调用Bot API发送拨号消息。

前端代码

const dialPhone = async () => {
  // 向你的后端发送拨号请求,需携带当前用户的chatId(可从Telegram.WebApp.initData中解析)
  const chatId = Telegram.WebApp.initDataUnsafe.user.id;
  await fetch('https://你的后端地址/api/trigger-dial', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ 
      chat_id: chatId, 
      phone: '+14231231' 
    })
  });
}

后端代码(Node.js示例)

const express = require('express');
const { Telegraf } = require('telegraf');
const app = express();
app.use(express.json());

const bot = new Telegraf('你的Bot Token');

app.post('/api/trigger-dial', async (req, res) => {
  const { chat_id, phone } = req.body;
  try {
    await bot.telegram.sendMessage(
      chat_id,
      `点击拨号:<a href="tel:${phone}">${phone}</a>`,
      { parse_mode: 'HTML' }
    );
    res.status(200).send({ success: true });
  } catch (err) {
    res.status(500).send({ error: err.message });
  }
});

app.listen(3000);

原理说明

Telegram客户端本身完全支持tel:协议,但WebApp的WebView被限制访问这类原生协议。通过Bot发送带链接的消息,相当于让用户在Telegram主客户端环境中操作,自然就能正常唤起拨号功能。

内容的提问来源于stack exchange,提问作者aki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 19:33:19