justdmitry / NetTelegramBotApi

C# client library for building Telegram bot
MIT License
74 stars 28 forks source link

forwardMessage #44

Closed behnia1996 closed 7 years ago

behnia1996 commented 7 years ago

Hello How can I forward a message from a channel in my bot? I find ID of channel and messageId but when use forwardMessage request in (await bot.makeRequestAsynd(myReq)) has error.

Text Error: Exeption: Exception thrown: 'NetTelegramBotApi.BotRequestException' in mscorlib.dll ("Request failed (status code 400): Bad Request: chat not found")

justdmitry commented 7 years ago

According to docs you need from_chat_id as @channelname. Check that you don't forgot to add @ before channelname.

I tried to forward message from channel to chat with bot and want it to be re-forwarded back to same chat with this code:

if (update.Message.ForwardFromChat != null)
{
    var req = new ForwardMessage(
        update.Message.Chat.Id, 
        "@" + update.Message.ForwardFromChat.Username, 
        update.Message.ForwardFromMessageId.Value);
    bot.MakeRequestAsync(req).Wait();
}

And it works - bot re-forwarded message to me.

justdmitry commented 7 years ago

Also I tried with chat id instead of channel name:

var req = new ForwardMessage(
    update.Message.Chat.Id, 
    update.Message.ForwardFromChat.Id, 
    update.Message.ForwardFromMessageId.Value);

Also works.

behnia1996 commented 7 years ago

Thank you for your help. It was OK. I have another question.

I can save editedMessage in bot, but I can't set editedMessage to null. If editedMessage haven't null value, my server is busy because update.EditedMessage haven't null value and in a lot of updates editedMessage have'nt null value.

On 2/16/17, Dmitry Popov notifications@github.com wrote:

Also I tried with chat id instead of channel name:

var req = new ForwardMessage(
    update.Message.Chat.Id,
    update.Message.ForwardFromChat.Id,
    update.Message.ForwardFromMessageId.Value);

Also works.

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/justdmitry/NetTelegramBotApi/issues/44#issuecomment-280321095

justdmitry commented 7 years ago

Please clarify what was wrong in your code and what "was Ok"? You forgot to add "@" before channelname?

About EditedMessages - please create separate issue with more details, I don't understand what the problem is.

behnia1996 commented 7 years ago

No, my problem in messageID section. But I did not know I should add "@" before channelname. I use channelChatID in my bot.

my code for submit editedMessage is:

if (update.EditedMessage != null) { if (update.EditedMessage.Text != "1" && update.EditedMessage.Text != "2" && update.EditedMessage.Text != "3" && update.EditedMessage.Text != "4" && update.EditedMessage.Text != "5" && update.EditedMessage.Text != "6") { dsLib.Point.updateAnatomicalAnswer (update.EditedMessage.Text, update.EditedMessage.MessageId); var sendMessage = new SendMessage (update.EditedMessage.Chat.Id, "Your Answer was changed"+update.UpdateId.ToString()) { ReplyMarkup = days }; await bot.MakeRequestAsync (sendMessage); update.EditedMessage.Text = "1"; continue; } continue; }

But after change the message in my database this "If" also repeated until bot have a new update. This repetition makes my server is busy and message "Your answer was changed" is send to user.

I want to that message will only be sent once.

On 2/21/17, Dmitry Popov notifications@github.com wrote:

Please clarify what was wrong in your code and what "was Ok"? You forgot to add "@" before channelname?

About EditedMessages - please create separate issue with more details, I don't understand what the problem is.

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/justdmitry/NetTelegramBotApi/issues/44#issuecomment-281342434

justdmitry commented 7 years ago

Please do not mix different problems in one issue.