- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我写了一个机器人,它会询问你的名字并将其写在照片上并发送给你并且它有效。但问题是当机器人上有多个用户时
它不起作用并且崩溃了,我想知道如何分离用户的输入和输出。(就像每个连接的用户都得到一个单独的 session ,因为现在一切都发生在一个 session 中并且它崩溃了)这是我的代码:
void bot_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
KeyboardButton[] btns = new KeyboardButton[1];
btns[0] = new KeyboardButton("ساخت عکس");
if(e.Message.Text=="ساخت عکس")
{
bot.SendTextMessageAsync(e.Message.From.Id, "نام خود را وارد کنید", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0);
// e.Message.Text = null;
shart = 1;
}
else
{
if (shart == 0)
{
Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup markup = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup(btns);
bot.SendTextMessageAsync(e.Message.From.Id, "برای شروع و ساخت عکس روی دکمه ساخت عکس کلید کنید", Telegram.Bot.Types.Enums.ParseMode.Default, false, false, 0, markup);
}
if (shart==1)
{
bot.StartReceiving();
bot.OnMessage += bot_OnMessage1;
}
}
}
void bot_OnMessage1(object sender, Telegram.Bot.Args.MessageEventArgs a)
{
string watermarkText = a.Message.Text;
//Get the file name.
string fileName = "C:\\temp\\01.jpg";
//Read the File into a Bitmap.
using (Bitmap bmp = new Bitmap(fileName))
{
using (Graphics grp = Graphics.FromImage(bmp))
{
//Set the Color of the Watermark text.
Brush brush = new SolidBrush(Color.White);
//Set the Font and its size.
Font font = new System.Drawing.Font("Arial", 50, FontStyle.Bold, GraphicsUnit.Pixel);
//Determine the size of the Watermark text.
SizeF textSize = new SizeF();
textSize = grp.MeasureString(watermarkText, font);
//Position the text and draw it on the image.
Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 10)));
grp.DrawString(watermarkText, font, brush, position);
bmp.Save("c:\\temp\\postpic.jpg", ImageFormat.Png);
using (FileStream fs = new FileStream("c:\\temp\\postpic.jpg", FileMode.Open))
{
fs.CanTimeout.ToString();
FileToSend fileToSend = new FileToSend("postpic.jpg", fs);
// var = FileToSend fts = new FileToSend("postpic", fs);
var rep = bot.SendPhotoAsync(a.Message.From.Id, fileToSend, "این عکس را پست کنید").Result;
}
}
}
}
}
最佳答案
您正在为每个用户编写(并随后从中读取)完全相同的文件:
mp.Save("c:\\temp\\postpic.jpg"
您需要为每个用户提供一个唯一 文件名。或者更好的是,根本不使用文件。您可能只使用本地内存流,而根本不会让文件堆满磁盘。
关于c# - 如何在 C# 中处理 Telegram bot 上的多个用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46908506/
我在网上看到有一些程序可以使用 Telegram CLI。 我想在他们之间做出选择 对于 Telegram bot API,有更多文档解释其功能,但对于 CLI,解释其特性的文档不多 似乎唯一了解的方
当我从按钮获得触发器时,我正在尝试使用 Telethon 发送 Telegram 消息。 当由 NewMessage 事件等事件触发时,我的 Telethon 方法工作正常,但是如何使用其他触发器(即
API 对象 User有房产language_code - Telegram 如何确定用户的语言,以及如何更改它? 我希望根据 language_code 为用户创建响应语言,但我不确定我是否可以信任
我有很多 Telegram channel ,他们以 24\7 的格式发送消息 “购买 usdjpy sl 145.2 tp 167.4” “eurusd 卖出 sl 145.2 tp 167.4”
我对Telegram机器人有疑问。 我需要键盘和嵌入式键盘,是否可以同时启用这两个功能? 最佳答案 根据Telegram documentation,当前不可能同时为reply_markup传递两个或
有人知道 Telegram 如何制作丰富的预览吗?了解它对我正在进行的开发非常有用。它是服务器端的特性,所以我认为代码不可用。不是吗? 最佳答案 它使用 Open Graph protocol :ht
Telegram是一种基于云的聊天服务。他们所有的客户端都是开源的。我想知道是否有办法在我自己的服务器上托管“私有(private)” Telegram 服务。 如果没有,是否有任何东西可以提供 te
为了发送常规消息,我使用 - const uri = `https://api.telegram.org/bot${token}/sendMessage?chat_id=${channelId}&
我正在尝试创建一个机器人,它可以读取/接收特定 channel 中的所有消息并将它们发送给我。我的问题是我找不到在我的机器人中访问这些消息的方法 重要的是: 我不是该 channel 的管理员或创建者
任何人都可以告诉我如何从我的 Telegram Bot 获取有关用户的信息。想象一下我的机器人是我 channel 中的管理员用户,我想获取我的 channel 用户列表或在新用户加入时引起注意。我怎
举个例子,我知道这个帐户存在“https://t.me/everexio ”,但当我单击查看时,它失败,并显示“没有包含您提供的用户名的 Telegram 帐户。”我在不同的群体中多次看到过这个问题。
我知道有一些特殊的网站,例如 Youtube、Vimeo 和...,我可以将我的视频上传到其中一个网站,并将其链接放在 Telegram 的消息中,在下面显示其大视频预览消息并通过其 InApp-Pl
我有一个机器人可以创建包含用户提供的一些 URL 的消息。Telegram 为这些 url 创建链接预览。预览已缓存。 有时 url 的内容发生变化,那么 Telegram 提供的预览就过时了。所以我
telegram 提供了一种衡量 channel 消息浏览量的方法。我很好奇是否有一种方法可以衡量特定群体每月的每月活跃用户或总独立浏览量。 最佳答案 简短回答:是。 您可以使用许多在线工具或机器人分
我如何在 Telegram 机器人上创建一个三划线菜单,类似于他们对 Jobs 机器人所做的那样?它应该与此类似: 我们如何称呼这种菜单? 最佳答案 您可以使用机器人父亲命令添加将显示在菜单上的命令。
网站telegram如何给登录用户发送消息? Telegram Login for Websites Telegram bots are a powerful communication tool,
我想连接一个简单的 Telegram Bot 来读取来自群组(我不是管理员)的消息。我已经将机器人添加到组中,但它不起作用。 这是我在 Python 中的代码: import telepot from
我想使用它的 deep linking 通过 Telegram 设置身份验证接口(interface)。 为了进行身份验证,在我的应用中,我要求用户点击如下链接: https://telegram.m
Telegram 中是否有任何事件 API 机器人 或 核心检测谁查看了用户或 channel 或群组或机器人配置文件? 一些机器人和应用程序声称他们可以做到这一点,但我没有在 Telegram AP
我正在尝试通过电报bot中的SendVoice方法发送语音消息,但是它将语音作为文档文件发送(而不是播放)。 ffmpeg将ogg文件转换为opus编码。 https://api.telegram.o
我是一名优秀的程序员,十分优秀!