From 2decec05375d36aefaa8262f008b3308f5796472 Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Sat, 22 Dec 2018 15:08:06 +0800 Subject: [PATCH] Use message sender ID for replying, additionally remove the keyboard after a bill is paid --- purjolok.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/purjolok.php b/purjolok.php index 73b43f1..acd6a42 100644 --- a/purjolok.php +++ b/purjolok.php @@ -49,7 +49,8 @@ if ($between = getBetween(reveal($message), '[billid]')) { imap_delete(getInbox('Utilities/' . getMessageSender(getTelegram()->getWebhookUpdates()) . ' To Pay'), $messages[0]['uid'], FT_UID); getTelegram()->sendMessage([ 'chat_id' => getTelegram()->getWebhookUpdates()->get('message')->get('chat')->get('id'), - 'text' => "I marked " . getMessageSenderDisplayName(getTelegram()->getWebHookUpdates()) . " as having paid the " . strtolower($messages[0]['service']) . " bill, thanks!" + 'text' => "I marked " . getMessageSenderDisplayName(getTelegram()->getWebHookUpdates()) . " as having paid the " . strtolower($messages[0]['service']) . " bill, thanks!", + 'reply_markup' => json_encode(['remove_keyboard' => true]) ]); } @@ -137,17 +138,26 @@ getTelegram()->addCommand( FALSE )))]; + error_log(print_r($buttons, true)); + + if (!$buttons[0]) { + $this->replyWithMessage([ + 'text' => getMessageSenderDisplayName($this->getUpdate()). ' doesn\'t have any outstanding bills. Nice :)', + 'reply_markup' => json_encode(['remove_keyboard' => true]) + ]); + return; + } + $reply_markup = getTelegram()->replyKeyboardMarkup([ 'keyboard' => $buttons, 'resize_keyboard' => true, 'one_time_keyboard' => true, - 'remove_keyboard' => true, 'selective' => true ]); $this->replyWithMessage( [ - 'text' => '[' . getMessageSenderDisplayName($this->getUpdate()) . '](tg://user?id=' . getMessageSender($this->getUpdate()) . '), which bill did you want to pay?', + 'text' => '[' . getMessageSenderDisplayName($this->getUpdate()) . '](tg://user?id=' . getMessageSenderId($this->getUpdate()) . '), which bill did you want to pay?', 'parse_mode' => 'markdown', 'reply_markup' => $reply_markup ] -- 2.11.0