Reputation: 481
I've made a telegram bot using C# and Telegram.Bot library. I've made it "inline" in BotFather and set inlinefeedback to "enabled".
The problem is when a user choose an option from inline answer, InlineResultChosen event not firing, the message is sending to chat but nobody see it except sender itself. Also there are clocks in message box (or red exclamation point in mobile version). I am using inline voice messages, and they are can be listened by sender.
Here is my code:
internal class Program
{
private static readonly List<InlineQueryResult> _queryResults
= new List<InlineQueryResult>();
private static void Main(string[] args)
{
var key = "...";
var sounds = new Dictionary<string, string>();
sounds.Add("Sound one", "https://omg.lol/1.wav");
sounds.Add("Sound two", "https://omg.lol/2.wav");
foreach (var sound in sounds)
{
var voice = new InlineQueryResultVoice();
voice.Url = sound.Value;
voice.Title = sound.Key;
voice.Id = sound.Key;
_queryResults.Add(voice);
}
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += ProcessBot;
if (bw.IsBusy == false)
{
bw.RunWorkerAsync(key);
}
Console.ReadLine();
}
private static void ProcessBot(object sender, DoWorkEventArgs e)
{
try
{
var key = e.Argument as string;
var bot = new TelegramBotClient(key);
bot.OnInlineQuery += AnswerInlineQuery;
bot.OnInlineResultChosen += InlineResultChosen;
bot.OnReceiveError += ErrorRecieved;
bot.OnReceiveGeneralError += GeneralErrorReceived;
bot.StartReceiving();
Console.ReadLine();
bot.StopReceiving();
}
catch (Telegram.Bot.Exceptions.ApiRequestException ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
private static void GeneralErrorReceived(object sender, ReceiveGeneralErrorEventArgs e)
{
Console.WriteLine("Error catched: " + e.Exception.Message);
}
private static void ErrorRecieved(object sender, ReceiveErrorEventArgs e)
{
Console.WriteLine("Error catched: " + e.ApiRequestException.Message);
}
private static void InlineResultChosen(object sender, ChosenInlineResultEventArgs e)
{
var result = e.ChosenInlineResult;
Console.WriteLine($"Sent a voice message by {result.From.Username}");
}
private static async void AnswerInlineQuery(
object sender,
InlineQueryEventArgs queryEventArgs)
{
var bot = sender as TelegramBotClient;
var query = queryEventArgs.InlineQuery;
await bot.AnswerInlineQueryAsync(
query.Id,
_queryResults.ToArray(),
0);
}
}
Upvotes: 0
Views: 1255
Reputation: 481
I found the solution. It was my fail: voice messages was in wrong format. First I changed it to .OGG like described in Telegram developers documentation. But in this case sound does not work on MacOS and iOS! I've changed all my sounds to .MP3 format and now they are working both on PC and Macs. Only one problem now: it seems it doesn't work on Windows Phone 8.
Upvotes: 1