wechatapiresource.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:wechat-bot-skeleton-python 作者: edonosotti 项目源码 文件源码
def on_post(self, request, response):
        formatter = WeChatMessageFormatter()
        message = formatter.parse_incoming_message(request.bounded_stream.read())

        if message['valid']:
            # Queue the message for delayed processing
            self.db_manager.queue_message(message)
            # WeChat always requires incoming user messages to be acknowledged at
            # least with an empty string (empty strings are not shown to users),
            # see: https://chatbotsmagazine.com/building-chatbots-for-wechat-part-1-dba8f160349
            # In this sample app, we simulate a "Customer Service"-like scenario
            # providing an instant reply to the user, announcing that a complete
            # reply will follow.
            reply = "Thank you for your message. We will get back to you as soon as possible!"
            response.status = falcon.HTTP_200
            response.body = formatter.format_instant_reply(message, reply)
        else:
            response.status = falcon.HTTP_200
            response.body = "Message was sent in a wrong format."
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号