本文整理汇总了Python中temba.msgs.models.Msg.mark_handled方法的典型用法代码示例。如果您正苦于以下问题:Python Msg.mark_handled方法的具体用法?Python Msg.mark_handled怎么用?Python Msg.mark_handled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类temba.msgs.models.Msg
的用法示例。
在下文中一共展示了Msg.mark_handled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_message
# 需要导入模块: from temba.msgs.models import Msg [as 别名]
# 或者: from temba.msgs.models.Msg import mark_handled [as 别名]
def send_message(
self,
flow,
message,
restart_participants=False,
contact=None,
initiate_flow=False,
assert_reply=True,
assert_handle=True,
):
"""
Starts the flow, sends the message, returns the reply
"""
if not contact:
contact = self.contact
try:
if contact.is_test:
Contact.set_simulation(True)
incoming = self.create_msg(
direction=INCOMING, contact=contact, contact_urn=contact.get_urn(), text=message
)
# start the flow
if initiate_flow:
flow.start(
groups=[], contacts=[contact], restart_participants=restart_participants, start_msg=incoming
)
else:
flow.start(groups=[], contacts=[contact], restart_participants=restart_participants)
(handled, msgs) = Flow.find_and_handle(incoming)
Msg.mark_handled(incoming)
if assert_handle:
self.assertTrue(handled, "'%s' did not handle message as expected" % flow.name)
else:
self.assertFalse(handled, "'%s' handled message, was supposed to ignore" % flow.name)
# our message should have gotten a reply
if assert_reply:
replies = Msg.objects.filter(response_to=incoming).order_by("pk")
self.assertGreaterEqual(len(replies), 1)
if len(replies) == 1:
self.assertEqual(contact, replies.first().contact)
return replies.first().text
# if it's more than one, send back a list of replies
return [reply.text for reply in replies]
else:
# assert we got no reply
replies = Msg.objects.filter(response_to=incoming).order_by("pk")
self.assertFalse(replies)
return None
finally:
Contact.set_simulation(False)