How to use the werobot.parser.parse_user_msg function in WeRoBot

To help you get started, we’ve selected a few WeRoBot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github offu / WeRoBot / werobot / testing.py View on Github external
def send_xml(self, xml):
        message = parse_user_msg(xml)
        return self.send(message)
github offu / WeRoBot / tests / test_parser.py View on Github external
def test_subscribe_event():
    message = parse_user_msg(
        """
    
        
        
        123456789
        
        
    
    """
    )
    assert message.target == "toUser"
    assert message.source == "FromUser"
    assert message.time == 123456789
    assert message.type == "subscribe_event"

    message = parse_user_msg(
github offu / WeRoBot / tests / test_handler.py View on Github external
def test_image():
    @werobot.image
    def image(message):
        return '图片喵'

    message = parse_user_msg(
        """
        
            
            
            1348831860
            
            
            1234567890123456
        
        """
    )

    reply = werobot.get_reply(message)

    assert isinstance(reply, TextReply)
    assert reply._args['content'] == u'图片喵'
github offu / WeRoBot / tests / test_replies.py View on Github external
def test_wechat_reply():
    message = parse_user_msg(
        """
        
        
        
        1348831860
        
        
        
        1234567890123456
        
    """
    )
    s = to_binary("喵fdsjaklfsk")
    reply = WeChatReply(message=message, s=s)
    assert reply._args['source'] == 'toUser'
    assert reply._args['target'] == 'fromUser'
github offu / WeRoBot / tests / test_parser.py View on Github external
def test_card_pay_order_event():
    message = parse_user_msg(
        """
        
            
            
            1453295737
            
            
            
            
            1453295737
            0
            
            
            
            
github offu / WeRoBot / tests / test_parser.py View on Github external
def test_none_message():
    assert not parse_user_msg("")
github offu / WeRoBot / tests / test_parser.py View on Github external
def test_user_consume_card_event():
    message = parse_user_msg(
        """
        
              
              
            1472549042
              
              
              
              
              
              
              
              
              
              
github offu / WeRoBot / tests / test_parser.py View on Github external
"""
    
        
        
        123456789
        
        
    
    """
    )
    assert message.target == "toUser"
    assert message.source == "FromUser"
    assert message.time == 123456789
    assert message.type == "subscribe_event"

    message = parse_user_msg(
        """
    
        
        123456789
        
        
        
        
    
    """
    )
    assert message.target == "toUser"
    assert message.source == "FromUser"
    assert message.time == 123456789
    assert message.type == "subscribe_event"
    assert message.key == "qrscene_123123"
github offu / WeRoBot / tests / test_parser.py View on Github external
def test_unknown_event():
    message = parse_user_msg(
        """
    
        
        
        123456789
        
        
    
    """
    )
    assert message.target == "toUser"
    assert message.source == "FromUser"
    assert message.time == 123456789
    assert message.type == "unknown_event"
github JoneXiong / oejia_wx / controllers / routes.py View on Github external
def handle(self, **kwargs):
        if not self.entry:
            self.init()
        if not self.robot.check_signature(
            request.params.get("timestamp"),
            request.params.get("nonce"),
            request.params.get("signature")
        ):
            return abort(403)

        body = request.httprequest.data
        message = parse_user_msg(body)
        self.robot.logger.info("Receive message %s" % message)
        reply = self.robot.get_reply(message)
        if not reply:
            self.robot.logger.warning("No handler responded message %s"
                                % message)
            return ''
        _logger.info('>>> reply: %s'%reply)
        return reply