B
B
BadCats2020-12-31 20:12:06
C++ / C#
BadCats, 2020-12-31 20:12:06

Telegram Bot API not sending file?

With coming! (for everyone reading in 2020 - Happy New Year!)
I can't deal with the bot - I'm trying to send myself a file from my PC.
Actually, what is the essence of the bot: at home, on the wifi home network, there is Rasbery PI as a server, on which the server part with the bot is spinning in a cycle - the bot receives a url, by which you need to save the web page locally to an external usb connected to the raspberry. But, I also want to have access to the saved files not only on the home network, but to make a static ip on the raspberry (it also has apache and COPS (OPDS cataloger)) - I don’t want to, therefore, I organized “communication” all through the same bot:
Actually, "communication" with the bot (I know that you can make a keyboard with buttons, but this is more of a training project - for myself, and here it's even more interesting for me to make a bicycle)

if (e.Message.Text.StartsWith("$"))//command
            {
                switch (e.Message.Text)
                {
                    case "$help":
                        bot.SendTextMessageAsync(new Telegram.Bot.Types.ChatId(id), "send me some commands:\n $help  -to see commands list\n" +
                            "$books_log - to see list of saved books (from log file)\n $books_list - to see list of saved books(get files name from storage)\n $download - to download some article");
                        break;
                    case "$books_log":
                        bot.SendTextMessageAsync(new Telegram.Bot.Types.ChatId(id), File.ReadAllText("URLLogs.txt"));
                        break;
                    case "$books_list":
                        GetBooksList();
                        break;


                    default:
                        if (e.Message.Text.StartsWith("$download"))
                        {
                            string pathToFile = GetDownloadFilePath(e.Message.Text.Substring(e.Message.Text.IndexOf(" ") + 1), e);
                            try
                            {
                                if (File.Exists(pathToFile))
                                {
                                    Console.WriteLine("file exist");
                                }
                                else
                                {
                                    Console.WriteLine("file NOT exist");
                                }



                                using (var stream = File.OpenRead(pathToFile))
                                {
                                    InputOnlineFile iof = new InputOnlineFile(stream);
                                    iof.FileName = "";
                                    var send = bot.SendDocumentAsync(new Telegram.Bot.Types.ChatId(id), iof, "Сообщение");
                                }

                                //bot.SendDocumentAsync(new Telegram.Bot.Types.ChatId(id), new Telegram.Bot.Types.InputFiles.InputOnlineFile(pathToFile));

                            }
                            catch (Exception ex)
                            {

                                Console.WriteLine(ex);
                            }
                        }
                        break;
                }

                return false;
            }

The essence of the problem: the code works without errors, it is displayed in the console that the file exists, but the file itself (htm page) - I do not get it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2020-12-31
@AlexanderYudakov

Judging by the name of the method "SendTextMessageAsync", you should use "await" when calling it.
The same goes for calling the "SendDocumentAsync" method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question