Exemplo n.º 1
0
    def test_channellog(self):
        contact = self.create_contact("Test", "+250788383383")
        msg = Msg.create_outgoing(self.org, self.admin, contact, "This is a test message")
        msg = dict_to_struct('MockMsg', msg.as_task_json())

        with SegmentProfiler("Channel Log inserts (10,000)", self, force_profile=True):
            for i in range(10000):
                ChannelLog.log_success(msg, "Sent Message", method="GET", url="http://foo",
                                       request="GET http://foo", response="Ok", response_status="201")
Exemplo n.º 2
0
    def test_channellog(self):
        contact = self.create_contact("Test", "+250788383383")
        msg = Msg.create_outgoing(self.org, self.admin, contact,
                                  "This is a test message")
        msg = dict_to_struct('MockMsg', msg.as_task_json())

        with SegmentProfiler("Channel Log inserts (10,000)",
                             self,
                             force_profile=True):
            for i in range(10000):
                ChannelLog.log_success(msg,
                                       "Sent Message",
                                       method="GET",
                                       url="http://foo",
                                       request="GET http://foo",
                                       response="Ok",
                                       response_status="201")
Exemplo n.º 3
0
def send_broadcast(bcast,
                   *,
                   expressions_context=None,
                   response_to=None,
                   msg_type="I",
                   high_priority=False):
    """
    Only used for testing to approximate how mailroom sends a broadcast
    """
    from temba.contacts.models import Contact
    from temba.msgs.models import Msg, SENT, UnreachableException

    contacts = set(bcast.contacts.all())
    for group in bcast.groups.all():
        contacts.update(group.contacts.all())

    recipients = set(bcast.urns.all())

    for contact in contacts:
        if bcast.send_all:
            recipients.update(contact.urns.all())
        else:
            recipients.add(contact)

    for recipient in recipients:
        contact = recipient if isinstance(recipient,
                                          Contact) else recipient.contact

        text = bcast.get_translated_text(contact)
        media = get_translated_media(bcast, contact)
        quick_replies = get_translated_quick_replies(bcast, contact)

        if expressions_context is not None:
            message_context = expressions_context.copy()
            if "contact" not in message_context:
                message_context["contact"] = contact.build_expressions_context(
                )
        else:
            message_context = None

        try:
            Msg.create_outgoing(
                bcast.org,
                bcast.created_by,
                recipient,
                text,
                bcast,
                channel=bcast.channel,
                attachments=[media] if media else None,
                quick_replies=quick_replies,
                response_to=response_to,
                high_priority=high_priority,
                msg_type=msg_type,
                expressions_context=message_context,
            )
        except UnreachableException:
            pass

    bcast.recipient_count = len(recipients)
    bcast.status = SENT
    bcast.save(update_fields=("recipient_count", "status"))

    bcast.org.trigger_send(bcast.msgs.all())