AppWeb.TelegramBotClient
0.1.4
dotnet add package AppWeb.TelegramBotClient --version 0.1.4
NuGet\Install-Package AppWeb.TelegramBotClient -Version 0.1.4
<PackageReference Include="AppWeb.TelegramBotClient" Version="0.1.4" />
paket add AppWeb.TelegramBotClient --version 0.1.4
#r "nuget: AppWeb.TelegramBotClient, 0.1.4"
// Install AppWeb.TelegramBotClient as a Cake Addin #addin nuget:?package=AppWeb.TelegramBotClient&version=0.1.4 // Install AppWeb.TelegramBotClient as a Cake Tool #tool nuget:?package=AppWeb.TelegramBotClient&version=0.1.4
AppWeb.TelegramBotClient
This is a .Net Standard client for communication with the Telegram Bot API. The client is available through a nuget.
Project url: https://appweb.se/en/packages/telegram-bot-client
You will find Telegram bot api documentation at:
Installation
Nuget package https://www.nuget.org/packages/AppWeb.TelegramBotClient/
install-package AppWeb.TelegramBotClient
Supported telegram bot api endpoints:
- '/sendMessage' to send message to a chat by given chat_id
- '/getUpdates' get updates (messages) sent to the bot
- '/setWebhook' updates what webhook settings should be used.
- '/deleteWebhook' deletes your webhook configuration and you have to use /getUpdates instead
Important Note!
If '/setWebhook' is used you cannot receive updates through polling '/getUpdates' due to limitations in telegram bot api. You will also have to use a HTTPS connection for your webhook. Read more at: https://core.telegram.org/bots/api#setwebhook
Todo
- Implement more telegram bot api endpoints
- Nuget package
- Add tests
Coommand line tool for controling and test your bot
The provided project TelegramBotApiCMD provides you with tooling using the TelegramBotApiClient, using this you can test and configure your bot.
Available commands:
exit
to exit applicationgetupdates
to receive messageshelp
for helpdeletewebhook
to delete webhook configurationsetwebhook <webhookUrl>
to configure webhooksettoken <token>
to set token for current session
Example projects in solution
- One example of a .net core console application polling updates from bot api through '/getUpdates', it can also be used as a tool to configure your bot and read/send messages
- One example of a .net core web application setting webhook that receives updates and reply to the sender.
Example code for setting up webhook, see example project in solution
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
// Setup telegram client
TelegramClient telegramClient = new TelegramClient();
var authenticationToken = Configuration["Settings:authenticationToken"];
telegramClient.SetAuthenticationToken(authenticationToken);
// Set up webhook
string webhookUrl = Configuration["Settings:webhookUrl"];
int maxConnections = int.Parse(Configuration["Settings:maxConnections"]);
UpdateType[] allowedUpdates = { UpdateType.MessageUpdate };
telegramClient.SetWebhook(webhookUrl, maxConnections, allowedUpdates);
services.AddScoped<ITelegramClient>(client => telegramClient);
}
Example code receiving webhook update and sending a replying message, see example project in solution
[Route("api/[controller]")]
public class TelegramController : Controller
{
ITelegramClient _telegramClient;
public TelegramController(ITelegramClient telegramClient) {
_telegramClient = telegramClient;
}
// GET api/telegram/update/{token}
[HttpPost("update/{token}")]
public void Update([FromRoute]string token, [FromBody]Update update)
{
if (token != _telegramClient.GetAuthenticationToken())
return;
if(update != null && update.Message != null)
_telegramClient.SendMessage(update.Message.Chat.Id, $"I received your message: \"{update.Message.Text}\"");
return;
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Nuget packaging adjustments