Event Raise
Steps to reproduce
OnMessage
Expected behavior
In Looping I expect the Event Raise It used to work but after two execution,It is not working any more
hi, Do you use Echo or webhook? Please provide your code that we can help you more. thanks
`` private static void OnMessage(object sender, MessageEventArgs eMessage) { string payam = ""; // Get mesage sender information var message = eMessage.Message; // User sender = eMessage.Message.Chat.Username ?? eMessage.Message.From; var t = message.Chat.Id;
// g(message.Chat.Id.ToString());
Console.WriteLine(message.Text ?? "");
// If user joined to bot say welcome
if ((!string.IsNullOrEmpty(message.Text)) && (message.Text == "/start"))
{
string welcomeMessage = "به بات بوسترلند خوش آمدید";
// $"Welcome {message.From.Username} !{Environment.NewLine}My name is {Bot.Me.Username}{Environment.NewLine}I made using TeleBot : http://www.github.com/Fel0ny/TeleSharp";
_tBot.SendTextMessageAsync(message.Chat.Id.ToString(), welcomeMessage);
var usage = @"Usage:
/register - get register Code ";
_tBot.SendTextMessageAsync(message.Chat.Id, usage,
replyMarkup: new ReplyKeyboardHide());
return;
}
`public BoosterLandBot(string botApiToken) { _tBot = new Telegram.Bot.TelegramBotClient(botApiToken); BotUserName = _tBot.GetMeAsync().Result.Username; _tBot.OnMessage += OnMessage; _tBot.OnInlineQuery += OnInlineQuery; _tBot.OnReceiveError += BotOnReceiveError; }
please check the following :
- what I can get from provided code is that you made an object of TelegramBotClient with the name "Bot" but you used "_tBot" in the rest of your code.
- check your bot token again from BotFather
- also before checking the text of your message you should check your message type (MessageType.TextMessage)
the bot api is also correct :(
` static void Main(string[] args) { string apiToken = ConfigurationManager.AppSettings["apiToken"]; TeleBoosterLandLib.BoosterLandBot bot = new TeleBoosterLandLib.BoosterLandBot(apiToken); Console.WriteLine($"Hi, My Name is : {bot.BotUserName}");
string apiId = ConfigurationManager.AppSettings["apiToken"];
string apiHash = ConfigurationManager.AppSettings["apiHash"];
string userNumber = ConfigurationManager.AppSettings["userNumber"];
//ConnectToApi();
bot.startReceiving();
Console.ReadLine();
bot.stopReceiving();
}
private static Telegram.Bot.TelegramBotClient _tBot;
public string BotUserName { get; set; }
public BoosterLandBot(string botApiToken)
{
_tBot = new Telegram.Bot.TelegramBotClient(botApiToken);
BotUserName = _tBot.GetMeAsync().Result.Username;
_tBot.OnMessage += OnMessage;
_tBot.OnInlineQuery += OnInlineQuery;
_tBot.OnReceiveError += BotOnReceiveError;
}
private static void OnMessage(object sender, MessageEventArgs eMessage) { string payam = ""; // Get mesage sender information var message = eMessage.Message; // User sender = eMessage.Message.Chat.Username ?? eMessage.Message.From; var t = message.Chat.Id; }`
is there any way that I can see why onmessage is not raising?
I think it is because of pooling procedure as I have run this code yesterday, and it is working for a while but after some seconds doesnt handle any event
Hi, Sorry for my delay. During these days I am so busy. Do you use Visual studio? ( so you can put break point in your function and debug your program. ) Do you use your computer as server or use a host as server?
hi, Yes I am using visual studio,what happens is that there is no error ,it just doesn't receive messages (or handle messages) after some time.
Could it be that the execution of one event is still pending, but it doesnt continue? Because it won't fire multiple events to one handler simultaneously.