I am building a Kotlin telegram bot using the latest version of this Java SDK.
I am trying to send an invoice using Telegram internal currency stars
Their official docs say that in order to do this you need to specify currency="XTR"
and providerToken=""
to create a stars invoice
I do exactly like this and then get an error from the Telegram API:
.telegram.telegrambots.meta.exceptions.TelegramApiValidationException: ProviderToken parameter can't be empty in method: SendInvoice(chatId=149396481, messageThreadId=null, title=Пожертвуйте на приложениe, description=Пожертвование, payload=test, providerToken=, startParameter=, currency=XTR, prices=[LabeledPrice(label=Пожертвование, amount=1)], photoUrl=null, photoSize=null, photoWidth=null, photoHeight=null, needName=null, needPhoneNumber=null, needEmail=null, needShippingAddress=null, isFlexible=null, disableNotification=null, replyToMessageId=null, sendPhoneNumberToProvider=null, sendEmailToProvider=null, replyMarkup=null, providerData=null, allowSendingWithoutReply=null, maxTipAmount=null, suggestedTipAmounts=[], protectContent=null, replyParameters=null)
Questions:
- Has anyone seen this error before?
- How do you fix it? I don't want to setup an external payment provider and get the token. The docs say that with stars it should be possible.
Here's the code I use to build the SendInvoice
object
fun invoice(
chatId: String,
text: String,
starsAmount: Int,
isFlexible: Boolean = true
) = SendInvoice.builder()
.chatId(chatId)
.title(text)
.description("Пожертвование")
.prices(listOf(LabeledPrice.builder().label("Пожертвование").amount(starsAmount).build()))
.currency("XTR")
.providerToken("")
.payload("test")
.startParameter("")
.build()
}
I am building a Kotlin telegram bot using the latest version of this Java SDK.
I am trying to send an invoice using Telegram internal currency stars
Their official docs say that in order to do this you need to specify currency="XTR"
and providerToken=""
to create a stars invoice
I do exactly like this and then get an error from the Telegram API:
.telegram.telegrambots.meta.exceptions.TelegramApiValidationException: ProviderToken parameter can't be empty in method: SendInvoice(chatId=149396481, messageThreadId=null, title=Пожертвуйте на приложениe, description=Пожертвование, payload=test, providerToken=, startParameter=, currency=XTR, prices=[LabeledPrice(label=Пожертвование, amount=1)], photoUrl=null, photoSize=null, photoWidth=null, photoHeight=null, needName=null, needPhoneNumber=null, needEmail=null, needShippingAddress=null, isFlexible=null, disableNotification=null, replyToMessageId=null, sendPhoneNumberToProvider=null, sendEmailToProvider=null, replyMarkup=null, providerData=null, allowSendingWithoutReply=null, maxTipAmount=null, suggestedTipAmounts=[], protectContent=null, replyParameters=null)
Questions:
- Has anyone seen this error before?
- How do you fix it? I don't want to setup an external payment provider and get the token. The docs say that with stars it should be possible.
Here's the code I use to build the SendInvoice
object
fun invoice(
chatId: String,
text: String,
starsAmount: Int,
isFlexible: Boolean = true
) = SendInvoice.builder()
.chatId(chatId)
.title(text)
.description("Пожертвование")
.prices(listOf(LabeledPrice.builder().label("Пожертвование").amount(starsAmount).build()))
.currency("XTR")
.providerToken("")
.payload("test")
.startParameter("")
.build()
}
Share
edited Mar 8 at 9:31
Mark Rotteveel
110k229 gold badges156 silver badges224 bronze badges
asked Mar 7 at 15:47
Arthur KlezovichArthur Klezovich
2,8251 gold badge16 silver badges21 bronze badges
2 Answers
Reset to default 0From the official ChangeLog:
The parameter
provider_token
of the methods sendInvoice and createInvoiceLink must be omitted for payments in Telegram Stars.
But you're adding .providerToken("")
which isn't allowed, just remove those fields!
EDIT: Found the Github issue about this, should be working if you omit that field, the last comments shows this working example:
SendInvoice sendInvoice = SendInvoice
.builder()
.chatId(callbackQuery.getMessage().getChatId())
.title("title")
.description("Description ")
.payload(callbackQuery.getId() + "-" + System.currentTimeMillis())
.currency("XTR")
.price(LabeledPrice
.builder()
.label("Price")
.amount(100)
.build()
)
.build();
I've managed to get this code to somehow work. An invoice does get sent from my bot wit h this. The issue might to be caused by a bug in the Telegram SDK
specifically in the builder
class for SendInvoice
.
Solution key ideas:
- Build the object yourself instead of relying on the builder
class
- Fields payload
and providerToken
must not be null or empty (API rejects these values), so you can set them to some simple non-empty string and see if it works. It does.
fun invoice(
chatId: String,
text: String,
starsAmount: Int,
isFlexible: Boolean = true
) = SendInvoice().apply {
this.chatId = chatId
this.title = text
this.description = "Пожертвование"
prices = listOf(LabeledPrice.builder().label("Пожертвование").amount(starsAmount).build())
currency = "XTR"
payload = "pl"
providerToken = "x"
}