def get_last_attachment_url()

in apps/chat/src/constants/code-apps.ts [240:280]


def get_last_attachment_url(messages: List[Message]) -> str:
    for message in reversed(messages):
        if (
            message.custom_content is not None
            and message.custom_content.attachments is not None
        ):
            attachments = message.custom_content.attachments

            if attachments == []:
                continue

            if len(attachments) != 1:
                msg = "Only one attachment per message is supported"
                raise DIALException(
                    status_code=422,
                    message=msg,
                    display_message=msg,
                )

            attachment = attachments[0]

            url = attachment.url
            if url is None:
                msg = "Attachment is expected to be provided via a URL"
                raise DIALException(
                    status_code=422,
                    message=msg,
                    display_message=msg,
                )

            return url

    msg = "No attachment was found"
    raise DIALException(
        status_code=422,
        message=msg,
        display_message=msg,
    )
`,
  },
  endpoints: {