Example #1
0
class ThreadSetComponent(Component):
    clear: bool = element_field()
    error: bool = element_field()

    async def start(self) -> List[Entry]:
        if self.clear:
            self.thread.thread_data_1 = None
            self.thread.thread_data_2 = None
            self.thread.thread_data_3 = None
            self.thread.thread_data_4 = None
            self.thread.thread_data_5 = None
        else:
            self.thread.thread_data_1 = []
            self.thread.thread_data_2 = {}
            self.thread.thread_data_3 = {"key": None}
            self.thread.thread_data_4 = {"key1": "x", "key2": None}
            self.thread.thread_data_5 = [
                {},
                {
                    "key1": "x",
                    "key2": None,
                    "key3": [],
                    "key4": [1, None, {
                        "key5": None,
                        "key6": "y"
                    }],
                },
            ]
        if self.error:
            raise Exception("ERROR")
        else:
            return self.respond()
Example #2
0
class YesNoTileComponent(InteractiveComponent):
    text: str = element_field()
    composer: ComposerElementSpec = element_field(
        default_factory=ComposerElementSpec)

    async def start(self) -> List[Entry]:
        # Modeled after TileAskComponent
        buttons_specs = [
            ButtonElementSpec(text="Yes", result="Y"),
            ButtonElementSpec(text="No", result="N"),
        ]

        buttons = self.get_buttons_and_triggers(buttons_specs)
        triggers = buttons.triggers

        tiles = [TileEventSpec(buttons=buttons.buttons, title=self.text)]

        ask_tiles_event = TileAskEvent(
            button_style=TileButtonStyle.ACTION,
            layout=TileLayout.COLUMN,
            text=None,
            tiles=tiles,
        )

        return self.respond(ask_tiles_event, *triggers)
Example #3
0
class ControlIfEvenComponent(Component):
    if_even: int = element_field(signature=True)
    then: ComponentSpec = element_field()
    else_: ComponentSpec = element_field()

    async def start(self) -> List[Entry]:
        if self.if_even % 2 == 0:
            return self.flow_control_action(self.then)
        else:
            return self.flow_control_action(self.else_)
Example #4
0
class GuessInitComponent(Component):
    @dataclass
    class Response:
        result: int = response_field(sensitive=True)

    sensitive: bool = element_field(default=True)
    from_: int = element_field()
    to: int = element_field()

    async def start(self) -> List[Entry]:
        secret = randint(self.from_, self.to)
        return self.respond(data=self.Response(secret))
Example #5
0
class FloodComponent(InteractiveComponent):
    count: int = element_field(default=256)

    async def start(self) -> List[Entry]:
        return self.respond(
            *[SayEvent(text=f"Flood - {i}") for i in range(self.count)]
        )
class UserDisconnectComponent(Component):
    disconnect_user_id: str = element_field(signature=True)

    async def start(self) -> List[Entry]:
        await self.user.load(self.disconnect_user_id)
        self.user.orb_sessions = None
        return self.respond()
Example #7
0
class OrderDisplayComponent(Component):
    orders: List[Order] = element_field()

    async def start(self) -> List[Entry]:
        tiles = []
        triggers = []
        for order in self.orders:
            button = ButtonElementSpec(text="Select", result=order.id)
            buttons = self.get_buttons_and_triggers([button])
            triggers += buttons.triggers

            product = order.products[0]
            tile = TileEventSpec(
                title=product.name,
                image=TileImage(url=product.image),
                rows=[[
                    TileCell(
                        cell="Price",
                        value="${:,.2f}".format(product.price),
                    ),
                    TileCell(cell="Status", value=order.status.value),
                ]],
                buttons=buttons.buttons,
            )
            tiles.append(tile)

        event = TileAskEvent(
            # TODO: move to bot settings
            # composer=ComposerEventSpec(visibility=ComposerVisibility.HIDE),
            button_style=TileButtonStyle.TEXT,
            text=None,
            tiles=tiles,
            layout=TileLayout.ROW,
        )
        return self.respond(event, *triggers)
Example #8
0
class ZendeskSupportTicketUnlinkComponent(Component):
    integration: ZendeskSupportIntegrationRef = element_field()

    async def start(self) -> List[Entry]:
        await self.thread.unlink(integration_id=self.integration.ref)
        self.thread.mode = ThreadMode.BOT
        return self.respond()
Example #9
0
class UserClearComponent(Component):
    user_id: str = element_field()

    async def start(self) -> List[Entry]:
        await self.user.load(self.user_id)
        self.user.clear()
        return self.respond()
Example #10
0
class Data2Component(Component):
    data_1: Data1 = element_field()

    async def start(self) -> List[Entry]:
        data = Data1(x=self.data_1.x + 8,
                     y=Data1A(z={
                         **self.data_1.y.z, "qqq": 90
                     }))
        return self.respond(
            data=Data2ComponentResponse(result=data, extra="extra!"))
Example #11
0
class OrderGetComponent(Component):
    order_id: str = element_field()

    @dataclass
    class Response:
        result: Optional[Order] = response_field()

    async def start(self) -> List[Entry]:
        order = Order.get(id=self.order_id)
        return self.respond(data=self.Response(result=order))
Example #12
0
class OrderListComponent(Component):
    user_id: str = element_field()

    @dataclass
    class Response:
        result: List[Order] = response_field()

    async def start(self) -> List[Entry]:
        orders = list(Order.filter(user_id=self.user_id))
        return self.respond(data=self.Response(result=orders))
Example #13
0
class ProductGetComponent(Component):
    product_id: str = element_field()

    @dataclass
    class Response:
        result: Optional[Product] = response_field()

    async def start(self) -> List[Entry]:
        self.log.info(f"product_id: {self.product_id}")
        product = Product.get(id=self.product_id)
        return self.respond(data=self.Response(result=product))
Example #14
0
class SunshineConversationsJwtComponent(Component):
    @dataclass
    class Response:
        result: str

    integration: SunshineConversationsIntegrationRef = element_field()
    external_id: str = element_field()

    async def start(self) -> List[Entry]:
        integration: SunshineConversationsIntegration = await self.resolve(
            self.integration)
        result = jwt.encode(
            {
                "scope": "appUser",
                "userId": self.external_id
            },
            integration.secret,
            algorithm="HS256",
            headers={"kid": integration.key_id},
        )
        return self.respond(data=self.Response(result))
Example #15
0
class WelcomeComponentElement(Component):
    language: str = element_field()

    async def start(self) -> List[Entry]:
        if self.language == "en":
            text = "Welcome! Let's get started!"
        elif self.language == "fr":
            text = "Bienvenue! Commençons!"
        else:
            text = "🤔"
        text_event = SayEvent(text=text)
        return self.respond(text_event)
Example #16
0
class UserGetComponent(Component):
    user_id: str = element_field()

    @dataclass
    class Response:
        result: Optional[User] = response_field()

    async def start(self) -> List[Entry]:
        try:
            user = User.get(id=self.user_id)
        except ObjectDoesNotExist:
            user = None
        return self.respond(data=self.Response(result=user))
Example #17
0
class WitParseEntities(Component):
    entities: Optional[dict] = element_field(default=False)

    async def start(self) -> List[Entry]:
        if not self.entities:
            return self.respond(data={})

        return self.respond(
            data=dict(
                entities=[
                    {"name": entity["name"], "value": entity["body"]}
                    for entity in list(self.entities.values())[0]
                ]
            )
        )
Example #18
0
class SayUpperComponent(InteractiveComponent):
    say_upper: Optional[str] = element_field(signature=True)

    async def start(self) -> List[Entry]:
        say_event = SayEvent(text=self.say_upper.upper())
        return self.respond(say_event)