|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Conversations; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\Customer\UpdateRequest as CustomerUpdateRequest; |
|
6
|
|
|
use BotMan\BotMan\Messages\Incoming\Answer; |
|
7
|
|
|
use BotMan\Drivers\Telegram\Extensions\Keyboard; |
|
8
|
|
|
use BotMan\Drivers\Telegram\Extensions\KeyboardButton; |
|
9
|
|
|
|
|
10
|
|
|
class UpdateCustomerConversation extends RegisterCustomerConversation |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* {@inheritDoc} |
|
14
|
|
|
*/ |
|
15
|
|
|
public function run() |
|
16
|
|
|
{ |
|
17
|
|
|
return $this->askGender(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Ask the customer gender. |
|
22
|
|
|
* |
|
23
|
|
|
* @return $this |
|
24
|
|
|
*/ |
|
25
|
|
|
protected function askGender() |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->askRenderable('conversations.update-customer.confirm-gender', next: function (Answer $answer) { |
|
28
|
|
|
if (!$answer->isInteractiveMessageReply()) { |
|
29
|
|
|
return; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$this->setUserStorage(['gender' => $answer->getValue()]); |
|
33
|
|
|
|
|
34
|
|
|
return $this->askEmail(); |
|
35
|
|
|
}, additionalParameters: Keyboard::create(Keyboard::TYPE_INLINE)->resizeKeyboard()->addRow( |
|
36
|
|
|
KeyboardButton::create(view('conversations.start.reply-gender-male')->render())->callbackData('male'), |
|
37
|
|
|
KeyboardButton::create(view('conversations.start.reply-gender-female')->render())->callbackData('female') |
|
38
|
|
|
)->addRow( |
|
39
|
|
|
KeyboardButton::create(view('conversations.start.reply-gender-undefined')->render())->callbackData('unknown') |
|
40
|
|
|
)->toArray()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritDoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function askEmail(string $validationErrorMessage = null) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->displayValidationErrorMessage($validationErrorMessage); |
|
49
|
|
|
|
|
50
|
|
|
return $this->askRenderable('conversations.exchange.ask-email', function (Answer $answer) { |
|
51
|
|
|
$value = $answer->getText(); |
|
52
|
|
|
$validator = CustomerUpdateRequest::createValidator($value, 'email'); |
|
53
|
|
|
|
|
54
|
|
|
if ($validator->fails()) { |
|
55
|
|
|
return $this->askEmail($validator->errors()->first('email')); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
$this->setUserStorage(['email' => $validator->validated()['email']]); |
|
59
|
|
|
|
|
60
|
|
|
return $this->askFullName(); |
|
61
|
|
|
}); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* {@inheritDoc} |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function askPhone(string $validationErrorMessage = null) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->displayValidationErrorMessage($validationErrorMessage); |
|
70
|
|
|
|
|
71
|
|
|
return $this->askRenderable('conversations.register-customer.ask-phone', function () { |
|
72
|
|
|
$value = $this->getMessagePayload('contact.phone_number'); |
|
73
|
|
|
$validator = CustomerUpdateRequest::createValidator($value, 'phone'); |
|
74
|
|
|
|
|
75
|
|
|
if ($validator->fails()) { |
|
76
|
|
|
return $this->askPhone($validator->errors()->first('phone')); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$this->setUserStorage(['phone' => $validator->validated()['phone']]); |
|
80
|
|
|
|
|
81
|
|
|
return $this->askWhatsappPhone(); |
|
82
|
|
|
}, additionalParameters: ['reply_markup' => json_encode([ |
|
83
|
|
|
'keyboard' => [[['text' => '☎️ ' . trans('Send My Phone Number'), 'request_contact' => true]]], |
|
|
|
|
|
|
84
|
|
|
'resize_keyboard' => true, |
|
85
|
|
|
'one_time_keyboard' => true, |
|
86
|
|
|
'remove_keyboard' => true, |
|
87
|
|
|
])]); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|