当前位置: 首页 > news >正文

网站去哪备案5118和百度指数

网站去哪备案,5118和百度指数,去除链接wordpress,咸阳做网站公司电话接上一篇文章,我们在创建好telegram机器人后,开始开发小游戏或者mini App,那就避免不了登录功能。 公开链接 bot设置教程:https://lengmo714.top/6e79860b.html 参考教程参考教程,telegram已经给我们提供非常多的api,我们在获取用…

接上一篇文章,我们在创建好telegram机器人后,开始开发小游戏或者mini App,那就避免不了登录功能。

公开链接
bot设置教程:https://lengmo714.top/6e79860b.html
参考教程参考教程,telegram已经给我们提供非常多的api,我们在获取用户信息的时候只需要调用对应的api即可。

拉起登录

我这里主要是获取头像、id、名字和状态。
用到2个api,getChatMembergetUserProfilePhotos
用法分别如下:
获取头像:

  // 初始化头像URL为空字符串let photoUrl = '';try {// 获取头像const profilePhotos = await bot.api.getUserProfilePhotos(userId, { limit: 1 });if (profilePhotos.total_count > 0) {const fileId = profilePhotos.photos[0][0].file_id;const file = await bot.api.getFile(fileId);photoUrl = `https://api.telegram.org/file/bot${TOKEN}/${file.file_path}`;}} catch (error) {console.error("获取头像失败: ", error);}

获取登录id:

  let userInfo = '';let id = "";let name = "";try {const chatMember = await bot.api.getChatMember(ctx.chat.id, userId);id = chatMember.user.id;name = chatMember.user.first_name;userInfo = `信息:\nID: ${chatMember.user.id}\n名字: ${chatMember.user.first_name}\n用户名: ${chatMember.user.username}\n状态: ${chatMember.status}`;} catch (error) {console.error("获取信息失败: ", error);}if (photoUrl) {await ctx.reply(`头像链接: ${photoUrl}`);} else {await ctx.reply("未能获取头像。");}await ctx.reply(userInfo || "未能获取信息。");

完整代码

import { Bot, InlineKeyboard } from "https://deno.land/x/grammy@v1.25.0/mod.ts";const TOKEN = '';  // bot机器人的token
const bot = new Bot(TOKEN);// 处理 /start 命令
bot.command("start", async (ctx) => {const firstName = ctx.update.message.from.first_name;const userId = ctx.from.id;// 初始化头像URL为空字符串let photoUrl = '';try {// 获取头像信息const profilePhotos = await bot.api.getUserProfilePhotos(userId, { limit: 1 });if (profilePhotos.total_count > 0) {const fileId = profilePhotos.photos[0][0].file_id;const file = await bot.api.getFile(fileId);photoUrl = `https://api.telegram.org/file/bot${TOKEN}/${file.file_path}`;}} catch (error) {console.error("获取头像失败: ", error);}// 获取用户登录信息let userInfo = '';let id = "";let name = "";try {const chatMember = await bot.api.getChatMember(ctx.chat.id, userId);id = chatMember.user.id;name = chatMember.user.first_name;userInfo = `信息:\nID: ${chatMember.user.id}\n名字: ${chatMember.user.first_name}\n用户名: ${chatMember.user.username}\n状态: ${chatMember.status}`;} catch (error) {console.error("获取信息失败: ", error);}if (photoUrl) {await ctx.reply(`头像链接: ${photoUrl}`);} else {await ctx.reply("未能获取头像。");}await ctx.reply(userInfo || "未能获取信息。");
});// 启动机器人
bot.start();

运行代码看先现象

执行下面命令,运动代码

deno run --allow-net ts脚本.ts
http://www.hkea.cn/news/401372/

相关文章:

  • 长沙网页制作开发公司aso优化方案
  • 深圳罗湖网站制作成人电脑基础培训班
  • 无锡网站制作咨询深圳网站设计十年乐云seo
  • 大连城市建设网站seo优化顾问服务阿亮
  • 福州 网站建设沈阳seo关键词排名优化软件
  • 做网站还要买服务器吗镇江seo
  • 专门做特价的网站优化排名案例
  • 网站建设的一些问题友链交易交易平台
  • 创业初期要建立公司的网站吗seo排名优化代理
  • 做网站全屏尺寸是多少钱站长工具查询系统
  • 做企业平台的网站有哪些手机网站制作教程
  • 免费行情的软件大全下载北京公司排名seo
  • 网站联系方式要素qq群推广链接
  • div css 网站模板免费的云服务器有哪些
  • 35互联做网站好吗网店运营工作内容
  • 网站建设模拟软件营销培训课程内容
  • 深圳建网站兴田德润专业2023年最新新闻简短摘抄
  • 学校网站怎么查询录取百度相册登录入口
  • 自助建设彩票网站网址查询工具
  • 怎么创建网页的快捷方式seo入门版
  • 互联网企业网站网络优化
  • 山东手工活外发加工网四川二级站seo整站优化排名
  • 行业门户网站开发百度竞价怎么做效果好
  • 适合前端做项目的网站百度网盘搜索
  • 下载网站怎么下载广州网站定制多少钱
  • 西安攻略旅游自由行怎么玩北京seo软件
  • 汉川网站建设sem代运营
  • 装酷网装修平台东莞seo外包
  • 专门做图片的网站吗如何建网站要什么条件
  • 卢氏县住房和城乡建设局网站站长统计 站长统计