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

多种郑州网站建设如何快速推广网上国网

多种郑州网站建设,如何快速推广网上国网,杭州行业网页设计公司,携程旅行网网站策划书接上一篇文章,我们在创建好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/271417/

相关文章:

  • 免费网站建站WWW222国际军事最新消息今天
  • 做网站软件miscrosoft云服务器
  • 如何做盗版小说网站最经典的营销案例
  • 设计类的网站和简介关键词优化推广排名多少钱
  • 代理记账网站怎么做北京seo方法
  • cdr做网站企业网站建设的基本流程
  • 网站建设需要哪些硬件百度指数排名
  • 2017年网站开发用什么语言找培训机构的app
  • 澳门响应式网站建设seo入门黑帽培训教程
  • 有哪些网站可以做微商口碑营销案例2021
  • 百度推广要不要建网站网络平台建设及运营方案
  • 大型网站开发考试查网址
  • 网站建设业务市场营销论文搜索优化
  • 黄页88企业名录seo怎么优化武汉厂商
  • 触摸屏网站如何做泰州seo网络公司
  • 银川app购物网站制作公司搜狗收录入口
  • 做单页网站要多少钱wordpress免费网站
  • 网站建设性价比高优化设计官网
  • 电脑手机网站相互跳转西安seo关键词排名优化
  • 一般做网站用什么字体比较合适搜索引擎营销是什么
  • 去什么网站发贴做推广seo及网络推广招聘
  • 如何批量建站什么是互联网营销
  • 哈尔滨网站建设如何搭建一个网站平台
  • 哪些网站可以做任务网络营销推广的基本手段
  • 互联网舆情报告什么是seo营销
  • 餐饮商家做网站的好处沈阳关键词优化费用
  • 如何把网站的文字编辑网站页面优化内容包括哪些
  • 安徽做公司网站哪家好销售策略和营销策略
  • 做游戏都需要什么网站吗域名注册腾讯云
  • 北京建设厅网站谷歌关键词搜索