Skip to content

Instantly share code, notes, and snippets.

@immmdreza
Created March 3, 2022 09:12
Show Gist options
  • Save immmdreza/20df78d0b8aa112f475a3ecb5bbba784 to your computer and use it in GitHub Desktop.
Save immmdreza/20df78d0b8aa112f475a3ecb5bbba784 to your computer and use it in GitHub Desktop.
VB example of telegram bot,
Imports System.Threading
Imports Telegram.Bot
Imports Telegram.Bot.Extensions.Polling
Imports Telegram.Bot.Types
Imports Telegram.Bot.Types.Enums
Module Program
Sub Main()
Dim bot = New TelegramBotClient("BOT_TOKEN")
Dim cts = New CancellationTokenSource()
Dim options = New ReceiverOptions With {
.AllowedUpdates = Array.Empty(Of UpdateType)()
}
bot.StartReceiving(updateHandler:=AddressOf HandlerAsync,
errorHandler:=AddressOf ErrorAsync,
options,
cts.Token)
Console.ReadLine()
End Sub
Private Async Function HandlerAsync(botClient As ITelegramBotClient,
update As Update,
cancellationToken As CancellationToken) As Task
If update.Message IsNot Nothing Then
If Not String.IsNullOrEmpty(update.Message.Text) Then
Await botClient.SendTextMessageAsync(
update.Message.Chat.Id,
update.Message.Text,
cancellationToken:=cancellationToken)
End If
End If
End Function
Private Function ErrorAsync(botClient As ITelegramBotClient,
exception As Exception,
cancellationToken As CancellationToken) As Task
Console.WriteLine(exception)
Return Task.CompletedTask
End Function
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment