From 66f82b1eb989c2f0c635c76923b4cc73c95eaede Mon Sep 17 00:00:00 2001 From: pseusys Date: Fri, 22 Mar 2024 01:45:20 +0100 Subject: [PATCH] two attachment tutorials fixed --- tutorials/script/responses/2_buttons.py | 60 ++++++++++++++++--------- tutorials/script/responses/3_media.py | 10 ++--- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/tutorials/script/responses/2_buttons.py b/tutorials/script/responses/2_buttons.py index faa9f60bc..8d8635eb3 100644 --- a/tutorials/script/responses/2_buttons.py +++ b/tutorials/script/responses/2_buttons.py @@ -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"), + ] ] ), }, @@ -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"), + ] ] ), }, @@ -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"), + ] ] ), }, @@ -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"), + ] ] ) }, @@ -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"), + ] ] ), }, @@ -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"), + ] ] ), }, @@ -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"), + ] ] ), }, @@ -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"), + ] ] ), }, @@ -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"), + ] ] ), }, @@ -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}) # %% diff --git a/tutorials/script/responses/3_media.py b/tutorials/script/responses/3_media.py index 412363c14..4f46bb130 100644 --- a/tutorials/script/responses/3_media.py +++ b/tutorials/script/responses/3_media.py @@ -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 ( @@ -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()}, }, @@ -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)], ), ), ( @@ -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)], ), ), (