Skip to content

Commit

Permalink
feat(helpdesk): add cancel option
Browse files Browse the repository at this point in the history
  • Loading branch information
vas3k committed Jun 15, 2024
1 parent 0affa0a commit 9129008
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions helpdeskbot/handlers/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ class ReviewKeyboard(Enum):
class QuestionKeyboard(Enum):
TITLE = "👉 Заголовок"
BODY = "📝 Текст вопроса"
ROOM = "💬 Комната"
ROOM = "💬 Выбрать комнату"
CANCEL = "❌ Отменить"
REVIEW = "✅ Запостить"


question_markup = ReplyKeyboardMarkup([
[QuestionKeyboard.TITLE.value],
[QuestionKeyboard.BODY.value],
[QuestionKeyboard.ROOM.value],
[QuestionKeyboard.REVIEW.value],
[QuestionKeyboard.CANCEL.value, QuestionKeyboard.REVIEW.value],
])

# It can be either a keyboard key, or the input text from the user
Expand Down Expand Up @@ -178,6 +179,15 @@ def request_room_choose(update: Update, context: CallbackContext) -> State:
return State.INPUT_RESPONSE


def cancel_question(update: Update, context: CallbackContext) -> State:
send_reply(
update,
"🫡 Создание вопроса отменено. Можно начать заново — /start",
reply_markup=start_markup,
)
return ConversationHandler.END


def review_question(update: Update, context: CallbackContext) -> State:
data = QuestionDto.from_user_data(context.user_data)

Expand Down Expand Up @@ -286,16 +296,8 @@ def finish_review(update: Update, context: CallbackContext) -> State:
elif text == ReviewKeyboard.EDIT.value:
return edit_question(update, context)

elif text == ReviewKeyboard.CANCEL.value:
send_reply(
update,
"🫡 Создание вопроса отменено. Можно начать заново — /start",
reply_markup=start_markup,
)
return ConversationHandler.END

else:
raise Exception("😱 Неожиданная команда: " + text)
raise Exception(f"😱 Неожиданная команда. Можем начать заново - /start")


def fallback(update: Update, context: CallbackContext) -> State:
Expand Down Expand Up @@ -334,6 +336,10 @@ def __init__(self, command):
Filters.regex(f"^{QuestionKeyboard.ROOM.value}$"),
request_room_choose
),
MessageHandler(
Filters.regex(f"^{QuestionKeyboard.CANCEL.value}|{ReviewKeyboard.CANCEL.value}$"),
cancel_question
),
MessageHandler(
Filters.regex(f"^{QuestionKeyboard.REVIEW.value}$"),
review_question
Expand Down

0 comments on commit 9129008

Please sign in to comment.