你好我嘗試發送帶有yowsup但我一直沒成功,你可以幫我即時得到IndentationError:意外縮進謝謝試圖發送一個消息Yowsup的Python
從yowsup.layers.interface進口YowInterfaceLayer,ProtocolEntityCallback 從yowsup.layers.protocol_messages.protocolentities導入TextMessageProtocolEntity 從yowsup.common.tools導入JID
類EchoLayer(YowInterfaceLayer):
@ProtocolEntityCallback("message")
def onMessage(self, messageProtocolEntity):
if messageProtocolEntity.getType() == 'text':
self.onTextMessage(messageProtocolEntity)
reply = 1
messageEntity = TextMessageProtocolEntity(reply,to = messageProtocolEntity.getFrom())
self.toLower(messageEntity)
self.toLower(messageProtocolEntity.forward(messageProtocolEntity.getFrom()))
self.toLower(messageProtocolEntity.ack())
self.toLower(messageProtocolEntity.ack(True))
@ProtocolEntityCallback("receipt")
def onReceipt(self, entity):
self.toLower(entity.ack())
def onTextMessage(self,messageProtocolEntity):
# just print info
print("Echoing %s to %s" % (messageProtocolEntity.getBody(), messageProtocolEntity.getFrom(False)))