I am making a telegram bot that provides paid advanced access. I use the botman studio library.
There was a problem getting a response from telegrams "PreCheckoutQuery".
I went the following way:
1. Created a hierarchy of dialogs using buttons
*Main menu (MainConversation)
**some sub-menu
***some sub-sub-menu
***etc
*Payment (PaymentConversation)
*Help (HelpConversation)
2. I navigate through the menu sections using switch-case and the ask method:
$this->ask('some text', function (Answer $answer)
switch ($answer->getText()) {
case 'some function':
$this->bot->startConversation(new SomeConversation());
break;
case 'Payment':
$this->bot->startConversation(new PaymentConversation());
break;
case 'Help':
$this->bot->startConversation(new HelpConversation());
}
}, $this->keyboard());
3. Inside PaymentConversation this code:
public function invoice()
{
$invoice = [
'title' => 'asdf',
'description' => 'asdf',
'payload' => 'asdf',
'provider_token' => 'some token',
'currency' => 'USD',
'prices' => json_encode(array(array(
'label' => 'asdf',
'amount' => 100000
)))
];
$this->bot->sendRequest('sendInvoice', $invoice);
}
After sendRequest, the bot sends an invoice to which the user must respond. After the payment information is filled in, telegram sends an update "pre_checkout_query" to which I must answer using the answerPreCheckoutQuery method (more details) I don't understand how to properly force botman update to listen from telegrams inside the dialog.
At first I had the idea to just make a middleware that would track the PreCheckoutQuery in IncomingMessage, but I ran into the fact that the class does not understand this request and created a separate TelegramPreCheckoutQueryDriver that handles such messages. Now I can confirm the payment in the intermediary, but this greatly limits my actions. I would like to do this as part of a dialogue.
I see this algorithm:
- User clicked the Payments button
- The PaymentConversation dialog has started
- An invoice has been sent to the user
- The user fills in payment details and clicks pay
- Bot receives message with PreCheckoutQuery
- Bot returns pre_checkout_query_id value
- Bot sends answerPreCheckoutQuery
- The bot receives payment confirmation and writes information about it to the database
- The bot launches the MainConversation dialog
I would be very grateful for any help! Thank you!