Skip to content

Commit

Permalink
Update to v.0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbot-ai committed Jun 1, 2023
1 parent 7267dda commit 37e9f6a
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 6,119 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
poetry.lock

/.config/
/rasa/.rasa/
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ The bank is more interested in issuing cards with a cashback. That is why the Bo
3. Obtain your bot token in [Telegram](https://core.telegram.org/bots/tutorial#obtain-your-bot-token).

Also note, that current version of Maxbot requires python 3.9.
Maxbot is compatible with 64-bit Python versions 3.9 – 3.11 and runs on Unix/Linux, macOS/OS X and Windows.

But the `bank_bot example` depends on the [RASA](https://pypi.org/project/rasa/) package which does not support Python 3.11.
So you need Python 3.9 or 3.10 to run the example.


# Running locally
Expand Down Expand Up @@ -240,10 +243,9 @@ Open the file `bot.yaml` and make sure that the settings are correct (note, that
```
extensions:
quick_replies: {}
format:
babel:
locale: en_US
datetime:
tz: America/New_York
datetime: {}
jinja_loader: {}
rasa:
url: http://0.0.0.0:5005
Expand Down
5 changes: 2 additions & 3 deletions bank_bot/bot.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
extensions:
quick_replies: {}
format:
babel:
locale: en_US
datetime:
tz: America/New_York
datetime: {}
jinja_loader: {}
rasa:
url: http://0.0.0.0:5005
Expand Down
14 changes: 10 additions & 4 deletions bank_bot/dialog/booking.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ nodes:
{% if slots.zip|int % 2 == 0 %}
{% set slots.ask_changing_zip = 'not_used' %}
{% else %}
{% delete slots.ask_changing_zip %}
Sorry. I don't found bank branches nearby.
Sorry. I don't found bank branches nearby.
{% endif %}
- name: ask_changing_zip
Expand All @@ -60,9 +62,11 @@ nodes:
{% if intents.yes %}
{% delete slots.zip %}
Alright. Let's start over.
{% elif intents.no %}
{% set slots.bank_branches_not_found = true %}
<response />
{% endif %}
- name: bank_branch
Expand All @@ -77,9 +81,11 @@ nodes:
{% if slots.bank_branch < 1 or slots.bank_branch > 5 %}
I'm sorry but that's not a valid option.
<prompt_again />
{% else %}
{% set slots.slots_order = slots.slots_order + ["bank_branch"] %}
Okay, location {{ slots.bank_branch }} on the list.
{% endif %}
- name: comment
Expand All @@ -92,9 +98,9 @@ nodes:
slot_handlers:
- condition: intents.cancel
response: |
{% set slots.canceled = true %}
Ok, we'll stop there. No appointment will be made.
<response />
{% set slots.canceled = true %}
Ok, we'll stop there. No appointment will be made.
<response />
- condition: intents.go_back
response: |
{% if slots.slots_order %}
Expand Down
12 changes: 8 additions & 4 deletions bank_bot/dialog/cc_choosing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ nodes:
check_for: slot_in_focus and entities.cc_type
value: entities.cc_type.value|lower
prompt: |
I can help you find a credit card to suit your needs.<br />
We have credit cards to build credit, provide rewards,<br />
and help you save money.
<quick_replies>
<text>What are you looking for most in a credit card?</text>
<text>
I can help you find a credit card to suit your needs.
We have credit cards to build credit, provide rewards,
and help you save money.<br /><br />
What are you looking for most in a credit card?
</text>
<button>Rewards</button>
<button>Increase credit score</button>
<button>Save money</button>
Expand Down
6 changes: 3 additions & 3 deletions bank_bot/dialog/fallback.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ nodes:
- condition: digressing
label: everything_else_in_digressing
response: |
❗I'm having some trouble understanding what you mean. Rephrase, please!
❗I'm having some trouble understanding what you mean. Rephrase, please!
- condition: true
label: everything_else
response: |
❗Sorry. I don't get it. Please rephrase!
<jump_to node="main_menu" transition="response"/>
❗Sorry. I don't get it. Please rephrase!
<jump_to node="main_menu" transition="response"/>
17 changes: 10 additions & 7 deletions bank_bot/dialog/making_payment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ nodes:
- condition: intents.show_cards_info
response: |
{% if profile.cards.items() %}
Current cards limits:
Current cards limits:<br />
{% else %}
❗No cards founds :(
{% endif %}
{% for number, card in profile.cards.items() %}
Card #{{ card.number }}
Minimal payment: ${{ card.min_payment }}
Due date: {{ card.due|format_date }}
<br />
{% endfor %}
<jump_to node="main_menu" transition="response" />
Expand All @@ -31,21 +30,23 @@ nodes:
I can help you with credit card payments. <br />
Please select which credit card account you'd like to pay.
</text>
{% for cc_num in profile.cards.keys() %}
<button>Card #{{ cc_num }}</button>
{% endfor %}
</quick_replies>
found: |
{% if not profile.is_my_card(slots.card_number) %}
❗Card #{{ slots.card_number }} not found. Try again.
{% delete slots.card_number %}
<prompt_again />
{% else %}
{% set slots.card_selected = slots.card_number %}
Great, card is #{{ slots.card_number }}.
{% endif %}
- name: date
Expand All @@ -58,15 +59,16 @@ nodes:
is due on {{ profile.cards[slots.card_selected].due|format_date }}.<br />
You can choose one of the options below, or enter your preferred payment date.
</text>
<button>Today</button>
<button>Tomorrow</button>
</quick_replies>
found: |
{% if not profile.check_payment_date(slots.card_selected, slots.date|datetime) %}
{% delete slots.date %}
❗The date must be greater or equal than the current date and less than the due date.
<prompt_again />
❗The date must be greater or equal than the current date and less than the due date.
<prompt_again />
{% else %}
Okay, {{ slots.date|format_date }}!
Expand All @@ -79,7 +81,7 @@ nodes:
prompt: |
Your minimum payment for credit card #{{ slots.card_number }}<br />
is ${{ profile.cards[slots.card_number].min_payment }}.<br />
Your balance is ${{ profile.balance }}.
Your balance is ${{ profile.balance }}.<br />
How much would you like to pay on your credit card?
found: |
Expand All @@ -99,6 +101,7 @@ nodes:
<br />
Is this information correct?
</text>
<button>Yes</button>
<button>No</button>
</quick_replies>
Expand Down
3 changes: 2 additions & 1 deletion bank_bot/dialog/welcome.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ nodes:
label: main_menu
response: |
<quick_replies>
<text>I can help you with a number of banking tasks:</text>
<text>I can help you with a number of banking tasks</text>
<button>Making a credit card payment</button>
<button>Booking an appointment with a banker</button>
<button>Choosing a credit card</button>
Expand Down
7 changes: 4 additions & 3 deletions bank_bot/extensions/quick_replies.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Quick replies implementation for Telegram channel."""

from marshmallow import Schema, fields
from maxbot.maxml import markup
from telegram import KeyboardButton, ReplyKeyboardMarkup


class QuickRepliesCommand(Schema):
"""Text message with button list."""

# Text message sent to the user along with the button list.
text = fields.String(required=True, metadata={"maxml": "element"})
text = markup.Field(required=True, metadata={"maxml": "element"})

# Button titles to be sent to the user.
button = fields.List(fields.String)
Expand All @@ -17,7 +18,7 @@ class QuickRepliesCommand(Schema):
input_field_placeholder = fields.String(required=False)

# Requests clients to hide the keyboard as soon as it's been used.
one_time_keyboard = fields.Bool(required=False, missing=True)
one_time_keyboard = fields.Bool(required=False, missing=True, default=True)


class QuickRepliesExtension:
Expand All @@ -35,7 +36,7 @@ async def send_quick_replies(self, command: dict, dialog: dict):
keyboard = [[KeyboardButton(text)] for text in command["quick_replies"]["button"]]
await self.bot.send_message(
dialog["user_id"],
text=command["quick_replies"]["text"],
text=command["quick_replies"]["text"].render(),
reply_markup=ReplyKeyboardMarkup(
keyboard,
resize_keyboard=True,
Expand Down
Loading

0 comments on commit 37e9f6a

Please sign in to comment.