Example #1
0
 public static async Task <Message?> SendInvoiceAsync(this ITelegramBotClient bot, long chatId, string?title, string?description, string?payload, string?providertoken
                                                      , string?startParameter
                                                      , string?currency
                                                      , IEnumerable <LabeledPrice> prices
                                                      , string?providerData = null
                                                      , InlineKeyboardMarkup replyMarkup = null
                                                      , bool needPhone           = false
                                                      , bool needEmail           = false
                                                      , bool needShippingAddress = false
                                                      , bool needName            = false
                                                      , string?photoUrl          = null
                                                      , CancellationToken ct     = default(CancellationToken))
 {
     if (bot == null)
     {
         return(null);
     }
     return(await bot.SendInvoiceAsync(GetChat(bot, chatId), title, description, payload, providertoken, startParameter,
                                       currency, prices, providerData, replyMarkup, needPhone, needEmail, needShippingAddress, needName, photoUrl, ct));
 }
Example #2
0
        public static async Task <Message?> SendInvoiceAsync(this ITelegramBotClient bot, TelegramChatStatusDesc c, string?title, string?description, string?payload, string?providertoken
                                                             , string?startParameter
                                                             , string?currency
                                                             , IEnumerable <LabeledPrice> prices
                                                             , string?providerData = null
                                                             , InlineKeyboardMarkup replyMarkup = null
                                                             , bool needPhone           = false
                                                             , bool needEmail           = false
                                                             , bool needShippingAddress = false
                                                             , bool needName            = false
                                                             , string?photoUrl          = null
                                                             , CancellationToken ct     = default(CancellationToken))
        {
            if (bot == null)
            {
                return(null);
            }
            if (c == null)
            {
                return(null);
            }
            int editMessageId = c.LastMessageId;


            if (c.DeleteMessage)
            {
                if (await bot.DeleteMessageIdAsync(c, editMessageId))
                {
                    c.AnswerToMessageId = 0;
                }
                //try
                //{
                //	await bot.DeleteMessageAsync(c.ChatId, editMessageId, ct);
                //	c.AnswerToMessageId = 0;
                //}
                //catch (Exception exx)
                //{
                //}
            }

            if (c.ChatId?.Identifier == null)
            {
                log.Warn($"{c},{c.ChatId} has null identifier");
            }

            try
            {
                var invoice = await bot.SendInvoiceAsync(c.ChatId.Identifier ?? 0
                                                         , title : title
                                                         , description : description
                                                         , payload : payload
                                                         , providerToken : providertoken
                                                         , startParameter : startParameter
                                                         , currency : currency
                                                         , prices : prices
                                                         , providerData : providerData
                                                         , replyMarkup : replyMarkup
                                                         , needPhoneNumber : needPhone
                                                         , needEmail : needEmail
                                                         , needShippingAddress : needShippingAddress
                                                         , needName : needName
                                                         , photoUrl : photoUrl);

                if (invoice == null)
                {
                    return(null);
                }

                c.LastMessageId = invoice.MessageId;
                c.DeleteMessage = true; //next time this message must be deleted, because we cant edit an invoice message
                return(invoice);
            }
            catch (Exception e)
            {
                c.DeleteMessage = false;
                log.Debug($"Bot: {bot.BotId}, to: {c.ChatId} - Error SendInvoiceAsync", e);
                return(null);
            }
        }