Skip to content

Commit bd74eea

Browse files
committed
Add location and contact buttons to the Survey example
1 parent a29336e commit bd74eea

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/Commands/UserCommands/SurveyCommand.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,15 @@ public function execute()
150150
if (is_null($message->getLocation())) {
151151
$this->conversation->notes['state'] = 4;
152152
$this->conversation->update();
153-
154-
$data['text'] = 'Insert your home location (need location object):';
155-
$data['reply_markup'] = new ReplyKeyBoardHide(['selective' => true]);
153+
$data['reply_markup'] = new ReplyKeyboardMarkup([
154+
'keyboard' => [[
155+
[ 'text' => 'Share Location', 'request_location' => true ],
156+
]],
157+
'resize_keyboard' => true,
158+
'one_time_keyboard' => true,
159+
'selective' => true,
160+
]);
161+
$data['text'] = 'Share your location:';
156162
$result = Request::sendMessage($data);
157163
break;
158164
}
@@ -174,6 +180,27 @@ public function execute()
174180

175181
// no break
176182
case 6:
183+
if (is_null($message->getContact())) {
184+
$this->conversation->notes['state'] = 6;
185+
$this->conversation->update();
186+
187+
$data['text'] = 'Share your contact information:';
188+
$data['reply_markup'] = new ReplyKeyboardMarkup([
189+
'keyboard' => [[
190+
[ 'text' => 'Share Contact', 'request_contact' => true ],
191+
]],
192+
'resize_keyboard' => true,
193+
'one_time_keyboard' => true,
194+
'selective' => true,
195+
]);
196+
$result = Request::sendMessage($data);
197+
break;
198+
}
199+
$this->conversation->notes['phone_number'] = $message->getContact()->getPhoneNumber();
200+
201+
// no break
202+
case 7:
203+
$this->conversation->update();
177204
$out_text = '/Survey result:' . "\n";
178205
unset($this->conversation->notes['state']);
179206
foreach ($this->conversation->notes as $k => $v) {

0 commit comments

Comments
 (0)