GithubHelp home page GithubHelp logo

justdmitry / nettelegrambotapi Goto Github PK

View Code? Open in Web Editor NEW
73.0 73.0 28.0 267 KB

C# client library for building Telegram bot

License: MIT License

C# 77.54% HTML 22.46%
nuget telegram-bot telegram-bot-api

nettelegrambotapi's People

Contributors

dannysotzny avatar justdmitry avatar lunat1q avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nettelegrambotapi's Issues

SendMessage doesn't work.

string API_HASH;
long user;
string message = "text";
TelegramBot bot = new TelegramBot(API_HASH);
try
{
    Console.WriteLine(
        bot.MakeRequestAsync(new NetTelegramBotApi.Requests.SendMessage(user, message))
             .GetAwaiter()
             .GetResult()
             .From
             .FirstName);
}
catch (Exception e)
{
    Console.WriteLine(e.Message);
    Console.Write(e.StackTrace);
    Console.Write(e.InnerException);
}
Console.ReadLine();

It's sample of code. No exception, anything. Just doesn't work.

Wait code

Hi,
What is the reason for use of this code?
bot.MakeRequestAsync(reqAction).Wait();
System.Threading.Thread.Sleep(500);

Error in start bot

Hi,
today my bot not start and Gives the following error in this request (https://api.telegram.org/bot132020125:AAGkjcMkiYAg-NR3VPVyriP3ljheSqz1ZzI/getMe), i do not change any code ! is it possible telegram filter me?
when i enter url in my chrome i got this error : 504 Gateway Time-out , nginx/1.6.2

My error in c# :
StatusCode: 504, ReasonPhrase: 'Gateway Time-out', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Connection: keep-alive
Date: Sun, 06 Sep 2015 17:40:10 GMT
Server: nginx/1.6.2
Content-Length: 182
Content-Type: text/html
}

Not an issue, more a request

I really want to develop a server-side interface for a bot using PowerShell.
The only difficulty I am facing is, I cannot load the library NetTelegramBotApi.dll.
It seems the entry point is not declared.

Thanks in advance.

Update for `August 15, 2015` API changes

Telegram team made some changes in API, marked as August 15, 2015:

  • Added new type Voice and new method sendVoice for sending voice messages.
  • Earlier Audio and sendAudio should now be used for sending music files. Telegram clients will show such files in the in-app music player. If you were using sendAudio for your bot to send voice messages, please use sendVoice instead.
  • Added optional fields performer, title to the Audio object and sendAudio method.
  • Added optional field voice to the Message object.

Source: https://core.telegram.org/bots/api-changelog#august-15-2015

Process image sent by user

Hi,
How can i work and Analysis the photo that user sended in update.Message.Photo?
i want Analysis photo of user with QR code and return text.
thanks.

UTF8 file name error

hi when I want to send file with UTF8 filename, don't show correct file name,
for example my file name is فارسی.docx but at reception user show filename like: =?utf-8?B?RDpcVXNlcnNcQXBhY2hpXERvY3VtZW50c1zYrdmF2K8g2YXYutix2KjZii5kb2N4?=

В примере поле текста бывает null.

Поэтому тут иногда возникает ошибка:

if (update.Message.Text.Length % 2 == 0)
                                {
                                    bot.MakeRequest(new SendMessage(update.Message.Chat.Id, "Вы отправили " + update.Message.Text.Length + " символов."));
                                }
                                else
                                {
                                    bot.MakeRequest(new ForwardMessage(update.Message.Chat.Id, update.Message.Chat.Id, update.Message.MessageId));
                                }

Лучше сделать вот так:

if (update.Message.Text != null)
                            {
                                if (update.Message.Text.Length % 2 == 0)
                                {
                                    bot.MakeRequest(new SendMessage(update.Message.Chat.Id, "Вы отправили " + update.Message.Text.Length + " символов."));
                                }
                                else
                                {
                                    bot.MakeRequest(new ForwardMessage(update.Message.Chat.Id, update.Message.Chat.Id, update.Message.MessageId));
                                }
                            }

Update for 'September 7, 2015' API changes

Telegram team made some changes in API, marked as September 7, 2015:

  • You can now pass parameters using application/json (please note that this doesn't work for file uploads: use multipart/form-data to upload files).
  • Added very basic markdown support. New field parse_mode addded to sendMessage. For the moment messages with markdown will be displayed correctly only in Telegram for Android. Other official apps will catch up soon.

Source: https://core.telegram.org/bots/api-changelog#september-7-2015

inline mode for game

I think NetTelegramBotApi
does not have InlineQueryResultGame, if it has please help to create inline keyboard for games, this is not a bug exactly, but i think its an issue

thanks...

Send mediafiles

Please tell me how to send the media content to the message. For example, image

work keyboard Markup with command

hi and thanks for your project
i want use keyboard and set with command .it means when click on keys send command whth \ but dont show in message this message have command .can you help me how i do it?

Add users.getFullUser method

) Буду весьма признателен если все функции из users будут доступны

Update for July-2015 changes

Telegram team made some changes in API, marked as July 2015

  • The thumb field is now optional for Video, Sticker and Document objects
  • The API now supports both video and photo captions. The caption field has been removed from the Video object and added to the Message object instead.
  • caption and duration optional fields have been added to the sendVideo method.
  • Fixed typo: user_id in the Contact object is now correctly labeled as Integer, not String

Source: https://core.telegram.org/bots/api-changelog

Max Text Length

Hi,
What is max length of text allow telegram to send ? 4096 UTF8 characters ?

bot stopped after a while

hi, im running my bots with NetTelegramBotApi on a windows server 2008 R2
my robot is disabled after a short time which it is inactive and doesnt receive any pm

what do i do ?

new_chat_participant ??

Hi
how use this to make Welcome Message for Groups or when some Body left Group or change name send A message to Group ?

i cant use inlineKeyboard With CallBackData

hi
when i use inlineKeyboard with Url is work
but when i use CallBackData it is not work and it doesnt send any message in bot?
how is it?
and please tell about CallBackQuery? thanks

it's my code

 var reqAction = new SendMessage(update.Message.Chat.Id, "test") { 
 ReplyMarkup = new InlineKeyboardMarkup
 {
   InlineKeyboard = new[] {
             new[] { new InlineKeyboardButton {
                             Text="test", 
                             CallbackData="1"
                            }
                       }
              }
    }
  };
 bot.MakeRequestAsync(reqAction);
 continue;

New API

Hello
Pplease update your program API
telegram's API have some new tools but your bot api haven't them

Send audio as voice message

i try to get audio and then send it as voice message.
for this,i download the audio by GetFile() and then convert it to .ogg then send it as voice message
by SendVoice()
But my robot send nothing !
help Please.

forwardMessage

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")

Send pdf

Hi,
when i want send pdf file this error accourd
Value cannot be null.
Parameter name: content

using (var docData = Assembly.GetExecutingAssembly().GetManifestResourceStream("TelegramBotDemo.test.pdf"))
{

                                var req = new SendDocument(update.Message.Chat.Id, new FileToSend(docData, "test.pdf"));
                                var msg = bot.MakeRequestAsync(req).Result;
                                uploadedDocumentId = msg.Document.FileId;
                            }

Command work and web hook

Hi,
thanks for your good code.
i have 2 question :
1 - How do I use command with / in bot ?
2 - How do I use web hook?

Setting up Webhook on console application example

hi
i want to work with webhook
i tried in console app and use of self signed certifacation bot i realy dont undrstand how to set it up
please help me
this is very important for me
help please ...

thanks

IMAGE_PROCESS_FAILED when sending image

В общем даже не знаю зачем тут этот метод. Всегда возвращает null. Пробую загрузить картинку в Stream. По любому возвращает
{"ok":false,"error_code":400,"description":"Error: IMAGE_PROCESS_FAILED"}.

var data = Translit(city);
            try
            {
               data = "D:\\123";
                var reqAction = new SendChatAction(chat_id, "upload_photo");
                bot.MakeRequestAsync(reqAction).Wait();
                System.Threading.Thread.Sleep(500);
                System.Drawing.Image image = Image.FromFile(string.Format("{0}.png", data));
                using (MemoryStream stream = new MemoryStream())
                {
                    // Save image to stream.
                    image.Save(stream, ImageFormat.Bmp);


                    using (var photoData =Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("{0}.png", data)))
                    {
                        var req = new SendPhoto(chat_id, new FileToSend(stream, string.Format(".png", city)))
                        {
                            Caption = "Telegram_logo.png"
                        };
                        var msg = bot.MakeRequestAsync(req).Result;
                        uploadedPhotoId = msg.Photo.Last().FileId;
                    }
                }
            }

Triggering messages

Hi, I've just updated an old application using NetTelegramBotApi, and I would like to trigger a message to every user of my bot informing them about the changes and new functionalities. Is there a way I can do that without the need of expecting the user to start a conversation ?

thanks!

Send bitmap as photo

hi

i want to send bitmap variable type as a photo by NetTelegramBotApi:
Bitmap bmp;

using (var photoData = Assembly.GetExecutingAssembly().GetManifestResourceStream("InstagramPuzzleBot.Resources.sample.png"))
i want to send bitmap contents, what should i write instead of : Assembly.GetExecutingAssembly().GetManifestResourceStream("NetTelegramBotApi.t_logo.png
?

i used this bug i got error:

                                Stream mms = new MemoryStream();
                                Bitmap bmp = makePuzzle(address, ID); //function with bitmap return type
                                bmp.Save(mms, System.Drawing.Imaging.ImageFormat.Bmp);

                                var reqAction = new SendChatAction(update.Message.Chat.Id, "upload_photo");
                                bot.MakeRequestAsync(reqAction).Wait();
                                System.Threading.Thread.Sleep(500);
                                using (var photoData = mms)
                                {
                                    var req = new SendPhoto(update.Message.Chat.Id, new FileToSend(photoData, "sample.png"))
                                    {
                                        Caption = "samplephoto"
                                    };
                                    var msg = bot.MakeRequestAsync(req).Result;
                                    SamplePhotoID = msg.Photo.Last().FileId;
                                }

Timeout property in the MakeRequest don't work?

Please,

I am trying use the Timeout property in the MakeRequestAsync to call GetUpdates but don't work. And I went to see the source code and not finded the property in the function.

She is used? My internet is unstable and I receive errors in all the time.
Thanks!

Как сделать чтобы бот ждал моих действий?

В демо примере подсказок не нашел.

if (text == "/Погода")
                    {
                        bot.MakeRequestAsync(new SendMessage(update.Message.Chat.Id, "Введите название города в котором хотите посмотреть погоду.")).Wait();

// Как сделать так чтобы он ждал отправки текста?
                        System.Threading.Thread.Sleep(500);
                        if (text != "")
                        {
                         ....
                       }

Error while sending big documents

Hi,
When i want to send document in line var msg = bot.MakeRequestAsync(req).Result; i have error :
One or more errors occurred. (How to see the original error?)
my file is pdf and size is 1.7 mb !!!

this is my code , it happens with file 1.7 mb only !!! for 500 k is ok ! please help me
using (var docData = File.OpenRead(FilePath))
{

var req = new SendDocument(update.Message.Chat.Id, new FileToSend(docData, Path.GetFileName(FilePath)));
var msg = bot.MakeRequestAsync(req).Result;
uploadedDocumentId = msg.Document.FileId;
}

InlineKeyboardMarkup Support

the new InlineKeyboardMarkup is not implemented
also the callback_query option is missing

great job! just missing some new stuff

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.