Skip to content

Commit

Permalink
feat: add robot.templatesendjobfinish_event (#544)
Browse files Browse the repository at this point in the history
* add robot.templatesendjobfinish_event to werobot/robot.py.

* add tests about robot.templatesendjobfinish_event

* add robot.templatesendjobfinish_event document in handlers.rst
  • Loading branch information
mywaiting authored Mar 3, 2020
1 parent c5f194e commit 6deee64
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ WeRoBot会将合法的请求发送给 handlers 依次执行。
:func:`robot.update_member_card <werobot.robot.BaseRoBot.update_member_card>` 会员卡积分余额发生变动 (Event)
:func:`robot.card_sku_remind <werobot.robot.BaseRoBot.card_sku_remind>` 库存警告 (Event)
:func:`robot.card_pay_order <werobot.robot.BaseRoBot.card_pay_order>` 券点发生变动 (Event)
:func:`robot.templatesendjobfinish_event <werobot.robot.BaseRoBot.templatesendjobfinish_event>` 模板信息推送事件 (Event)
:func:`robot.submit_membercard_user_info <werobot.robot.BaseRoBot.submit_membercard_user_info>` 激活卡券 (Event)
:func:`robot.location_event <werobot.robot.BaseRoBot.location_event>` 上报位置 (Event)
:func:`robot.unknown_event <werobot.robot.BaseRoBot.unknown_event>` 未知类型 (Event)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,31 @@ def submit_membercard_user_info():
assert reply._args['content'] == u'现在醒一醒还来得及'


def test_templatesendjobfinish_event_handler():
@werobot.templatesendjobfinish_event
def templatesendjobfinish_event():
return '喵喵~模板消息已经推送'

message = parse_user_msg(
"""
<xml>
<ToUserName><![CDATA[gh_7f083739789a]]></ToUserName>
<FromUserName><![CDATA[oia2TjuEGTNoeX76QEjQNrcURxG8]]></FromUserName>
<CreateTime>1395658920</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[TEMPLATESENDJOBFINISH]]></Event>
<MsgID>200163836</MsgID>
<Status><![CDATA[success]]></Status>
</xml>
"""
)

reply = werobot.get_reply(message)

assert isinstance(reply, TextReply)
assert reply._args['content'] == u'喵喵~模板消息已经推送'


def test_unknown_event():
@werobot.unknown_event
def unknown_event(message):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def test_location_event():
assert message.precision == 119.385040


def test_template_send_job_finish_event():
def test_templatesendjobfinish_event():
message = parse_user_msg(
"""
<xml>
Expand Down
7 changes: 7 additions & 0 deletions werobot/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class BaseRoBot(object):
'update_member_card_event',
'card_sku_remind_event',
'card_pay_order_event',
'templatesendjobfinish_event',
'submit_membercard_user_info_event', # event
'text',
'image',
Expand Down Expand Up @@ -455,6 +456,12 @@ def submit_membercard_user_info(self, f):
self.add_handler(f, type='submit_membercard_user_info_event')
return f

def templatesendjobfinish_event(self, f):
"""在模版消息发送任务完成后,微信服务器会将是否送达成功作为通知,发送到开发者中心中填写的服务器配置地址中
"""
self.add_handler(f, type='templatesendjobfinish_event')
return f

def unknown_event(self, f):
"""
为未知类型 ``(unknown_event)`` 事件添加一个 handler 方法的装饰器。
Expand Down

0 comments on commit 6deee64

Please sign in to comment.