# Define echo layerfrom yowsup.layers.protocol_messages.protocolentities import TextMessageProtocolEntity from yowsup.layers import YowLayer class EchoLayer(YowLayer): def receive(self, protocolEntity): if protocolEntity.getTag() == "message": self.onMessage(protocolEntity) def onMessage(self, messageProtocolEntity): outgoingMessageProtocolEntity = TextMessageProtocolEntity( messageProtocolEntity.getBody(), to = messageProtocolEntity.getFrom() ) self.toLower(outgoingMessageProtocolEntity) from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback from yowsup.layers.protocol_messages.protocolentities import TextMessageProtocolEntity from yowsup.layers.protocol_receipts.protocolentities import OutgoingReceiptProtocolEntity from yowsup.layers.protocol_acks.protocolentities import OutgoingAckProtocolEntity class EchoLayer(YowInterfaceLayer): # Expects sending and receive protocolentity @ProtocolEntityCallback("message") # No nid receive method def onMessage(self, messageProtocolEntity): receipt = OutgoingReceiptProtocolEntity( messageProtocolEntity.getId(), messageProtocolEntity.getFrom(), 'read', messageProtocolEntity.getParticipant() ) outgoingMessageProtocolEntity = TextMessageProtocolEntity( messageProtocolEntity.getBody(), to = messageProtocolEntity.getFrom() ) self.toLower(receipt) self.toLower(outgoingMessageProtocolEntity) @ProtocolEntityCallback("receipt"): def onReceipt(self, entity): ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", entity.getType(), entity.getFrom()) self.toLower(ack)
Saturday, March 4, 2017
YowSup
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment