Skip to content

Commit

Permalink
two attachment tutorials fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
pseusys committed Mar 22, 2024
1 parent 11cc1a3 commit 66f82b1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
60 changes: 39 additions & 21 deletions tutorials/script/responses/2_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="5", payload="5"),
Button(text="4", payload="4"),
[
Button(text="5", data="5"),
Button(text="4", data="4"),
]
]
),
},
Expand All @@ -77,8 +79,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="38", payload="38"),
Button(text="48", payload="48"),
[
Button(text="38", data="38"),
Button(text="48", data="48"),
]
]
),
},
Expand All @@ -97,8 +101,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="229", payload="229"),
Button(text="283", payload="283"),
[
Button(text="229", data="229"),
Button(text="283", data="283"),
]
]
),
},
Expand Down Expand Up @@ -126,8 +132,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="5", payload="5"),
Button(text="4", payload="4"),
[
Button(text="5", data="5"),
Button(text="4", data="4"),
]
]
)
},
Expand All @@ -143,8 +151,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="5", payload="5"),
Button(text="4", payload="4"),
[
Button(text="5", data="5"),
Button(text="4", data="4"),
]
]
),
},
Expand All @@ -160,8 +170,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="38", payload="38"),
Button(text="48", payload="48"),
[
Button(text="38", data="38"),
Button(text="48", data="48"),
]
]
),
},
Expand All @@ -177,8 +189,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="38", payload="38"),
Button(text="48", payload="48"),
[
Button(text="38", data="38"),
Button(text="48", data="48"),
]
]
),
},
Expand All @@ -194,8 +208,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="229", payload="229"),
Button(text="283", payload="283"),
[
Button(text="229", data="229"),
Button(text="283", data="283"),
]
]
),
},
Expand All @@ -211,8 +227,10 @@ def payload_check_inner(ctx: Context, _: Pipeline):
"misc": {
"ui": Keyboard(
buttons=[
Button(text="229", payload="229"),
Button(text="283", payload="283"),
[
Button(text="229", data="229"),
Button(text="283", data="283"),
]
]
),
},
Expand All @@ -230,15 +248,15 @@ def process_request(ctx: Context):
and ctx.last_response.misc
and ctx.last_response.misc.get("ui")
)
if ui and ui.buttons:
if ui and ui.buttons[0]:
try:
chosen_button = ui.buttons[int(ctx.last_request.text)]
chosen_button = ui.buttons[0][int(ctx.last_request.text)]
except (IndexError, ValueError):
raise ValueError(
"Type in the index of the correct option "
"to choose from the buttons."
)
ctx.last_request = Message(misc={"payload": chosen_button.payload})
ctx.last_request = Message(misc={"payload": chosen_button.data})


# %%
Expand Down
10 changes: 5 additions & 5 deletions tutorials/script/responses/3_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from dff.script import RESPONSE, TRANSITIONS
from dff.script.conditions import std_conditions as cnd

from dff.script.core.message import Attachments, Image, Message
from dff.script.core.message import Image, Message

from dff.pipeline import Pipeline
from dff.utils.testing import (
Expand Down Expand Up @@ -57,14 +57,14 @@
"send_one": {
RESPONSE: Message(
text="here's my picture!",
attachments=Attachments(files=[Image(source=img_url)]),
attachments=[Image(source=img_url)],
),
TRANSITIONS: {("root", "fallback"): cnd.true()},
},
"send_many": {
RESPONSE: Message(
text="Look at my pictures",
attachments=Attachments(files=[Image(source=img_url)] * 10),
attachments=[Image(source=img_url)],
),
TRANSITIONS: {("root", "fallback"): cnd.true()},
},
Expand Down Expand Up @@ -93,7 +93,7 @@
Message(img_url),
Message(
text="here's my picture!",
attachments=Attachments(files=[Image(source=img_url)]),
attachments=[Image(source=img_url)],
),
),
(
Expand All @@ -105,7 +105,7 @@
Message(f"{img_url} repeat 10 times"),
Message(
text="Look at my pictures",
attachments=Attachments(files=[Image(source=img_url)] * 10),
attachments=[Image(source=img_url)],
),
),
(
Expand Down

0 comments on commit 66f82b1

Please sign in to comment.