conversion of examples in vb.net
dotmax opened this issue · 5 comments
Good morning, it is possible to have the examples (at least the simplest one) converted into VB.net code ?
best regards
Max
Sorry, but that requires someone who knows VB...
Sure!!
Vb programmers (like me) nowadays are very rare...
I ended up in making a "frankenstein"
I start the bot with c# (core) code provided by examples.
On the message handlers i call a method in a separate class/project written in VB.net
Quite inelegant, but it seems to work.
Let me know if someone is interested. I will post the code.
@dotmax i'm very interest, my Bot code works great with 16.0.2, then i switch to 17.0 and i have many errors but i don't find examples that i know what i must change in my code.
This is my little sample
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telegram.Bot;
using Telegram.Bot.Types.ReplyMarkups;
namespace WindowTelegramBot
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
TelegramBotClient BotClient;
[Obsolete]
private void Form1_Load(object sender, EventArgs e)
{
BotClient = new TelegramBotClient("XXX");
BotClient.OnMessage += BotClient_OnMessage;
BotClient.OnCallbackQuery += BotClient_OnCallbackQuery;
BotClient.StartReceiving();
BotClient.StopReceiving();
}
[Obsolete]
private async void BotClient_OnCallbackQuery(object sender, Telegram.Bot.Args.CallbackQueryEventArgs e)
{
var id = e.CallbackQuery.From.Id;
var fullname = e.CallbackQuery.From.FirstName + " " + e.CallbackQuery.From.LastName;
var text = e.CallbackQuery.Data;
switch (text)
{
case "Ok":
await BotClient.EditMessageTextAsync(id,e.CallbackQuery.Message.MessageId, "\n<b>IT SCHOOL ONLINE</b>\n" + "\n Ok!", Telegram.Bot.Types.Enums.ParseMode.Html, replyMarkup: null);
await BotClient.EditMessageReplyMarkupAsync(id, e.CallbackQuery.Message.MessageId, replyMarkup: EditButton("Ok", fullname));
break;
case "No":
await BotClient.EditMessageTextAsync(id, e.CallbackQuery.Message.MessageId, "\n<b>IT SCHOOL ONLINE</b>\n" + "\n No!", Telegram.Bot.Types.Enums.ParseMode.Html, replyMarkup: null);
await BotClient.EditMessageReplyMarkupAsync(id, e.CallbackQuery.Message.MessageId, replyMarkup: EditButton("No", fullname));
break;
}
}
[Obsolete]
private async void BotClient_OnMessage(object sender, Telegram.Bot.Args.MessageEventArgs e)
{
var id = e.Message.From.Id;
var fullname = e.Message.From.FirstName + " " + e.Message.From.LastName;
var test = e.Message.Text.ToString();
switch (test)
{
case "Hello":
await BotClient.SendTextMessageAsync(id, "\n<b>IT SCHOOL ONLINE</b>\n" + "\n Hello " + fullname + " ! [" + id + "]", Telegram.Bot.Types.Enums.ParseMode.Html,replyMarkup:CreateButton());
break;
case "How are you?":
await BotClient.SendTextMessageAsync(id, "\n<b>IT SCHOOL ONLINE</b>\n" + "\n I'm Ok!", Telegram.Bot.Types.Enums.ParseMode.Html, replyMarkup: CreateButton());
break;
}
}
[Obsolete]
private void btnStart_Click(object sender, EventArgs e)
{
BotClient.StartReceiving();
}
[Obsolete]
private void btnStop_Click(object sender, EventArgs e)
{
BotClient.StopReceiving();
}
public InlineKeyboardMarkup CreateButton()
{
List<InlineKeyboardButton> btn = new List<InlineKeyboardButton>();
btn.Add(new InlineKeyboardButton { Text = "Ok", CallbackData = "Ok"});
btn.Add(new InlineKeyboardButton { Text = "No", CallbackData = "No" });
var menu = new List<InlineKeyboardButton[]>();
menu.Add(new[] { btn[0], btn[1] });
var main = new InlineKeyboardMarkup(menu.ToArray());
return main;
}
public InlineKeyboardMarkup EditButton(string btnName, string name)
{
List<InlineKeyboardButton> btn = new List<InlineKeyboardButton>();
btn.Add(new InlineKeyboardButton { Text = btnName+"("+name+")", CallbackData = "000" });
var menu = new List<InlineKeyboardButton[]>();
menu.Add(new[] { btn[0] });
var main = new InlineKeyboardMarkup(menu.ToArray());
return main;
}
}
}
Thank you very much