def get_error_message( self, e: Exception, api: LedgerApi, message: Message, dialogue: BaseDialogue, ) -> LedgerApiMessage: """ Build an error message. :param e: the exception. :param api: the Ledger API. :param message: the request message. :return: an error message response. """ message = cast(LedgerApiMessage, message) dialogue = cast(LedgerApiDialogue, dialogue) response = LedgerApiMessage( performative=LedgerApiMessage.Performative.ERROR, message_id=message.message_id + 1, target=message.message_id, dialogue_reference=dialogue.dialogue_label.dialogue_reference, code=500, message=str(e), data=b"", ) response.counterparty = message.counterparty dialogue.update(response) return response
def __init__( self, dialogue_label: DialogueLabel, agent_address: Optional[Address] = None, role: Optional[Dialogue.Role] = None, ) -> None: """ Initialize a dialogue. :param dialogue_label: the identifier of the dialogue :param agent_address: the address of the agent for whom this dialogue is maintained :param role: the role of the agent this dialogue is maintained for :return: None """ Dialogue.__init__( self, dialogue_label=dialogue_label, agent_address=agent_address, role=role, rules=Dialogue.Rules( cast(FrozenSet[Message.Performative], self.INITIAL_PERFORMATIVES), cast(FrozenSet[Message.Performative], self.TERMINAL_PERFORMATIVES), cast( Dict[Message.Performative, FrozenSet[Message.Performative]], self.VALID_REPLIES, ), ), )
def __init__(self, dialogue_label: DialogueLabel, is_seller: bool, **kwargs) -> None: """ Initialize a dialogue label. :param dialogue_label: the identifier of the dialogue :param is_seller: indicates whether the agent associated with the dialogue is a seller or buyer :return: None """ BaseDialogue.__init__(self, dialogue_label=dialogue_label) self._is_seller = is_seller self._role = Dialogue.AgentRole.SELLER if is_seller else Dialogue.AgentRole.BUYER
def __init__(self, dialogue_label: DialogueLabel, is_seller: bool) -> None: """ Initialize a dialogue label. :param dialogue_label: the identifier of the dialogue :param is_seller: indicates whether the agent associated with the dialogue is a seller or buyer :return: None """ BaseDialogue.__init__(self, dialogue_label=dialogue_label) self._is_seller = is_seller self._role = 'seller' if is_seller else 'buyer' self._outgoing_messages = [] # type: List[Message] self._outgoing_messages_controller = [] # type: List[Message] self._incoming_messages = [] # type: List[Message]
def setup(cls): """Initialise the class.""" cls.dialogue_label = DialogueLabel(dialogue_reference=(str(0), ''), dialogue_opponent_pbk="opponent", dialogue_starter_pbk="starter") cls.dialogue = Dialogue(dialogue_label=cls.dialogue_label) cls.dialogues = Dialogues()