Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

Event Raise

Open npsniloo opened this issue 9 years ago • 11 comments

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

npsniloo avatar Dec 06 '16 08:12 npsniloo

hi, Do you use Echo or webhook? Please provide your code that we can help you more. thanks

matiuspico avatar Dec 06 '16 08:12 matiuspico

`` 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;
        }

npsniloo avatar Dec 06 '16 09:12 npsniloo

`public BoosterLandBot(string botApiToken) { _tBot = new Telegram.Bot.TelegramBotClient(botApiToken); BotUserName = _tBot.GetMeAsync().Result.Username; _tBot.OnMessage += OnMessage; _tBot.OnInlineQuery += OnInlineQuery; _tBot.OnReceiveError += BotOnReceiveError; }

npsniloo avatar Dec 06 '16 09:12 npsniloo

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)

matiuspico avatar Dec 06 '16 09:12 matiuspico

the bot api is also correct :(

npsniloo avatar Dec 06 '16 09:12 npsniloo

` 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; }`

npsniloo avatar Dec 06 '16 09:12 npsniloo

is there any way that I can see why onmessage is not raising?

npsniloo avatar Dec 06 '16 10:12 npsniloo

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

npsniloo avatar Dec 06 '16 11:12 npsniloo

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?

matiuspico avatar Dec 08 '16 11:12 matiuspico

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.

npsniloo avatar Dec 10 '16 06:12 npsniloo

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.

Olfi01 avatar Aug 25 '17 06:08 Olfi01