You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have seen on the code that when you send a test message
BotClient.SendTextMessageAsync(
chatId: new ChatId(Convert.ToInt32(idTelegram)),
text: texto,
parseMode: ParseMode.Markdown)
If this IdTelegram is not in BotChat, the wrapper throws an ChatNotFoundException.
On this excepction, in Telegram.Bot.Exceptions.ApiExceptionParser the information that elevates is only "chat not found".
I have seen that in the class Telegram.Bot.TelegramBotClient.MakeRequestAsync, a the end of the method, it reports apiResponse to ApiExceptionParser.
In this case of exception there aren´t any Parameter on the apiResponse.
If its possible to add more information to this exception, it could be implemented some thing like this:
if (!apiResponse.Ok)
{
string requestStr = JsonConvert.SerializeObject(request);
if (actualResponseStatusCode == HttpStatusCode.BadRequest)
{
Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(requestStr);
if (json.GetValue("chat_id") != null)
{
apiResponse.Parameters = new ResponseParameters();
apiResponse.Parameters.ChatId = Convert.ToInt64(json.GetValue("chat_id").ToString());
}
}
throw ApiExceptionParser.Parse(apiResponse);
}
Also I supose that ResponseParameters class has to be modified with new property ChatId like this:
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public long ChatId { get; set; }
In the class Telegram.Bot.Exceptions.ApiExceptionParser.ApiRequestException may be introduce a new if case for ChatNotFoundException:
if (isBadRequestError)
{
errorMessage = TruncateBadRequestErrorDescription(apiResponse.Description);
if (typeInfo.Type == typeof(InvalidParameterException))
{
string paramName = Regex.Match(apiResponse.Description, typeInfo.ErrorMessageRegex)
.Groups[InvalidParameterException.ParamGroupName]
.Value;
exception = new InvalidParameterException(paramName, errorMessage);
}
else
{
if (typeInfo.Type == typeof(ChatNotFoundException))
{
exception = new ChatNotFoundException(errorMessage, apiResponse.Parameters);
}
else
exception = Activator.CreateInstance(typeInfo.Type, errorMessage) as ApiRequestException;
}
}
public ChatNotFoundException(string message, Types.ResponseParameters parameters)
: base(message, parameters)
{
}
I think that is interesting to know if someone has left the BotChat to delete him from you database.
Do you know if exist any way to know if someone has left the BotChat before sending him a message?
Thank you very much for the wrapper. It works really good!!! :)
The text was updated successfully, but these errors were encountered:
We've tried the approach with custom exceptions on different error results and abandoned it since it relies heavily on parsing of error messages. And they are not a part of public API, they can change anytime rendering all custom exceptions useless.
I would like to request/propose a feature
I have seen on the code that when you send a test message
If this IdTelegram is not in BotChat, the wrapper throws an
ChatNotFoundException
.On this excepction, in
Telegram.Bot.Exceptions.ApiExceptionParser
the information that elevates is only "chat not found".I have seen that in the class
Telegram.Bot.TelegramBotClient.MakeRequestAsync
, a the end of the method, it reportsapiResponse
toApiExceptionParser
.In this case of exception there aren´t any
Parameter
on theapiResponse
.If its possible to add more information to this exception, it could be implemented some thing like this:
Also I supose that
ResponseParameters
class has to be modified with new propertyChatId
like this:In the class
Telegram.Bot.Exceptions.ApiExceptionParser.ApiRequestException
may be introduce a new if case forChatNotFoundException
:I think that is interesting to know if someone has left the BotChat to delete him from you database.
Do you know if exist any way to know if someone has left the BotChat before sending him a message?
Thank you very much for the wrapper. It works really good!!! :)
The text was updated successfully, but these errors were encountered: