telegram-bot-ruby
telegram-bot-ruby copied to clipboard
sendInvoice doesn't support prices array
Hi @atipugin,
@yulgolem was playing with Bot API 3.0 and found a bug. He was sending parameters as
params = {
chat_id: 1111111111,
title: 'Invoice title',
description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod',
payload: 'LWJK...',
provider_token: STRIPE_TOKEN,
start_parameter: 'WD6354FKJ...',
currency: 'USD',
prices: [{amount: 100, label: "PriceLabel_1" }, {amount: 200, label: "PriceLabel_2"}]
}
but Telegram returned an error
ok: "false", error_code: "400", description: "Bad Request: prices are not specified")
However a request with the same parameters made via Postman succeed and invoice was sent to chat.
That made me think that something is wrong with request body encoding.
sendInvoice
has prices
parameters which is an array of LabeledPrice.
After inspecting request body and decoding it I found that decoded request via Faraday looks like (I format it for readability):
chat_id=1111111111&
currency=USD&
description=Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod&
payload=LWJK...&
prices[][amount]=100&prices[][label]=PriceLabel_1&prices[][amount]=200&prices[][label]=PriceLabel_2&
provider_token=STRIPE_TOKEN&
start_parameter=WD6354FKJ...&
title=Invoice title
While Postman's decoded request body looks like:
chat_id=1111111111&
title=Invoice title&
description=Lorem+ipsum+dolor+sit+amet,+consectetur+adipisicing+elit,+sed+do+eiusmod&
payload=LWJK...&
provider_token=STRIPE_TOKEN&
currency=USD&
start_parameter=WD6354FKJ...&
prices=[{"amount":100,"label":"PriceLabel_1"},{"amount":200,"label":"PriceLabel_2"}]
Right now we are using url_encoded
Faraday's middleware and payload is sent as application/x-www-form-urlencoded
.
I tried to use json
middleware to send data as application/json
and it seems to fix the problem.
I will provide PR for this, just the problem to be stated and known.
Yep, I can confirm that. After using the gem from 0daf853969992b5a371b80847abc7b2723ef4481 the bug is gone and invoice is sent from bot to user.
Can confirm the bug, but even with the mentioned commit it doesnt seem to work.
@b1nary, I will take a look.
Confirm bug
@b1nary I checked ivanovaleksey's commit and it works fine.
I have the same problem. How to pass prices
to sendInvoice
properly?
@vladimirsazhin this is not implemented in the main repo yet.
As it's said above you can try to use a fork version just to make if it works. Though I don't recommend to switch to it entirely.
To merge it to the main repo we need to do a testing since request's content type changes from url_encoded
to json
. You can share your experience here if you will give to fork a try.
How can I access the conn
property of Telegram::Bot::Api
and configure adapter without forking the gem? Is it possible?
So I found temporary solution.
prices = JSON.generate([{label: 'Foo', amount: 2000}, {label: 'Bar', amount: 2400}])
bot.api.send_invoice(..., prices: prices)
{ "ok": false, "error_code": 400, "description": "Bad Request: expected Array of labeled prices" }
This error show me! How to fix it
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.