Exemplo n.º 1
0
    def handle_PUT_in_reply_to(self, request, payload, in_reply_to):
        user_account = request.getUser()
        conversation = yield self.get_conversation(user_account)

        reply_to = yield self.vumi_api.mdb.get_inbound_message(in_reply_to)
        if reply_to is None:
            self.client_error_response(request, 'Invalid in_reply_to value')
            return

        reply_to_mdh = MessageMetadataHelper(self.vumi_api, reply_to)
        try:
            msg_conversation_key = reply_to_mdh.get_conversation_key()
        except KeyError:
            log.warning('Invalid reply to message %r which has no conversation'
                        ' key' % (reply_to,))
            msg_conversation_key = None
        if msg_conversation_key != conversation.key:
            self.client_error_response(request, 'Invalid in_reply_to value')
            return

        msg_options = ReplyToOptions(payload)
        if not msg_options.is_valid:
            self.client_error_response(request, msg_options.error_msg)
            return

        continue_session = (msg_options.session_event
                            != TransportUserMessage.SESSION_CLOSE)
        helper_metadata = conversation.set_go_helper_metadata()
        helper_metadata.update(self.get_load_balancer_metadata(payload))

        msg = yield self.worker.reply_to(
            reply_to, msg_options.content, continue_session,
            helper_metadata=helper_metadata)

        self.successful_send_response(request, msg)
Exemplo n.º 2
0
    def handle_inbound(self, message, endpoint):
        optout_disabled = False
        msg_mdh = MessageMetadataHelper(self.vumi_api, message)
        if msg_mdh.tag is not None:
            tagpool_metadata = yield msg_mdh.get_tagpool_metadata()
            optout_disabled = tagpool_metadata.get("disable_global_opt_out", False)
        keyword = (message["content"] or "").strip()
        helper_metadata = message["helper_metadata"]
        optout_metadata = helper_metadata.setdefault("optout", {"optout": False})

        if not optout_disabled and self.casing(keyword) in self.optout_keywords:
            optout_metadata["optout"] = True
            optout_metadata["optout_keyword"] = self.casing(keyword)
        returnValue(message)
Exemplo n.º 3
0
 def assert_transaction(self, msg, direction, session_created):
     md = MessageMetadataHelper(self.vumi_helper.get_vumi_api(), msg)
     direction = {
         "inbound": BillingDispatcher.MESSAGE_DIRECTION_INBOUND,
         "outbound": BillingDispatcher.MESSAGE_DIRECTION_OUTBOUND,
     }[direction]
     self.assertEqual(self.billing_api.transactions, [{
         "account_number": md.get_account_key(),
         "message_id": msg["message_id"],
         "tag_pool_name": md.tag[0],
         "tag_name": md.tag[1],
         "message_direction": direction,
         "session_created": session_created,
     }])
Exemplo n.º 4
0
 def assert_transaction(self, msg, direction, session_created):
     md = MessageMetadataHelper(self.vumi_helper.get_vumi_api(), msg)
     direction = {
         "inbound": BillingDispatcher.MESSAGE_DIRECTION_INBOUND,
         "outbound": BillingDispatcher.MESSAGE_DIRECTION_OUTBOUND,
     }[direction]
     self.assertEqual(self.billing_api.transactions,
                      [{
                          "account_number": md.get_account_key(),
                          "message_id": msg["message_id"],
                          "tag_pool_name": md.tag[0],
                          "tag_name": md.tag[1],
                          "message_direction": direction,
                          "session_created": session_created,
                      }])
Exemplo n.º 5
0
 def add_md(self, msg, user_account=None, tag=None, is_paid=False):
     msg.payload.setdefault('helper_metadata', {})
     md = MessageMetadataHelper(self.vumi_helper.get_vumi_api(), msg)
     if user_account is not None:
         md.set_user_account(user_account)
     if tag is not None:
         md.set_tag(tag)
     if is_paid:
         md.set_paid()
Exemplo n.º 6
0
    def handle_inbound(self, message, endpoint):
        optout_disabled = False
        msg_mdh = MessageMetadataHelper(self.vumi_api, message)
        if msg_mdh.tag is not None:
            tagpool_metadata = yield msg_mdh.get_tagpool_metadata()
            optout_disabled = tagpool_metadata.get('disable_global_opt_out',
                                                   False)
        keyword = (message['content'] or '').strip()
        helper_metadata = message['helper_metadata']
        optout_metadata = helper_metadata.setdefault('optout',
                                                     {'optout': False})

        if (not optout_disabled
                and self.casing(keyword) in self.optout_keywords):
            optout_metadata['optout'] = True
            optout_metadata['optout_keyword'] = self.casing(keyword)
        returnValue(message)
Exemplo n.º 7
0
 def add_md(self, msg, user_account=None, tag=None, is_paid=False):
     msg.payload.setdefault('helper_metadata', {})
     md = MessageMetadataHelper(self.vumi_helper.get_vumi_api(), msg)
     if user_account is not None:
         md.set_user_account(user_account)
     if tag is not None:
         md.set_tag(tag)
     if is_paid:
         md.set_paid()
Exemplo n.º 8
0
    def filter_and_scrub_messages(self, messages, include_sensitive, scrubber):
        """
        Filter and scrub the given messages.

        :param list messages:
            The list of messages to filter and scrub.
        :param bool include_sensitive:
            Whether or not to include hidden messages.
        :param callable scrubber:
            The scrubber to use on hidden messages. Should return a message
            object or None.
        """
        collection = []
        for message in messages:
            # vumi message is an attribute on the inbound message object
            msg = message.msg
            msg_mdh = MessageMetadataHelper(self.api, msg)
            if not msg_mdh.is_sensitive():
                collection.append(msg)
            elif include_sensitive:
                scrubbed_msg = scrubber(msg)
                if scrubbed_msg:
                    collection.append(scrubbed_msg)
        return collection
Exemplo n.º 9
0
 def mk_md(self, message=None, go_metadata=None, optout_metadata=None):
     if message is None:
         message = self.mk_msg(go_metadata, optout_metadata)
     return MessageMetadataHelper(self.vumi_helper.get_vumi_api(), message)
Exemplo n.º 10
0
 def add_router_metadata(self, msg, router):
     msg.payload.setdefault('helper_metadata', {})
     md = MessageMetadataHelper(None, msg)
     md.set_router_info(router.router_type, router.key)
     md.set_user_account(router.user_account.key)
Exemplo n.º 11
0
 def get_batch_id(self, msg):
     mdh = MessageMetadataHelper(self.vumi_api, msg)
     conversation = yield mdh.get_conversation()
     returnValue(conversation.batch.key)
Exemplo n.º 12
0
 def add_conversation_metadata(self, msg, conv):
     msg.payload.setdefault('helper_metadata', {})
     md = MessageMetadataHelper(None, msg)
     md.set_conversation_info(conv.conversation_type, conv.key)
     md.set_user_account(conv.user_account.key)
Exemplo n.º 13
0
 def get_batch_id(self, msg):
     mdh = MessageMetadataHelper(self.vumi_api, msg)
     router = yield mdh.get_router()
     returnValue(router.batch.key)
Exemplo n.º 14
0
 def get_batch_id(self, msg):
     mdh = MessageMetadataHelper(self.vumi_api, msg)
     router = yield mdh.get_router()
     returnValue(router.batch.key)
Exemplo n.º 15
0
 def get_batch_id(self, msg):
     mdh = MessageMetadataHelper(self.vumi_api, msg)
     conversation = yield mdh.get_conversation()
     returnValue(conversation.batch.key)
Exemplo n.º 16
0
 def add_router_metadata(self, msg, router):
     msg.payload.setdefault('helper_metadata', {})
     md = MessageMetadataHelper(None, msg)
     md.set_router_info(router.router_type, router.key)
     md.set_user_account(router.user_account.key)
Exemplo n.º 17
0
 def add_conversation_metadata(self, msg, conv):
     msg.payload.setdefault('helper_metadata', {})
     md = MessageMetadataHelper(None, msg)
     md.set_conversation_info(conv.conversation_type, conv.key)
     md.set_user_account(conv.user_account.key)
Exemplo n.º 18
0
 def get_metadata_helper(self, msg):
     return MessageMetadataHelper(self.vumi_api, msg)
Exemplo n.º 19
0
 def with_md(self, msg, user_account=None, conv=None, router=None,
             endpoint=None, tag=None, hops=None, outbound_hops_from=None,
             is_paid=False, is_reply_to_unroutable=False):
     msg.payload.setdefault('helper_metadata', {})
     md = MessageMetadataHelper(self.vumi_helper.get_vumi_api(), msg)
     if user_account is not None:
         md.set_user_account(user_account)
     if conv is not None:
         conv_type, conv_key = conv
         md.set_conversation_info(conv_type, conv_key)
         md.set_user_account(self.user_account_key)
     if router is not None:
         router_type, router_key = router
         md.set_router_info(router_type, router_key)
         md.set_user_account(self.user_account_key)
     if endpoint is None:
         endpoint = msg.get_routing_endpoint()
     msg.set_routing_endpoint(endpoint)
     if tag is not None:
         md.set_tag(tag)
     if is_paid:
         md.set_paid()
     if hops is not None:
         rmeta = RoutingMetadata(msg)
         for src, dst in zip(hops[:-1], hops[1:]):
             rmeta.push_hop(src, dst)
     if outbound_hops_from is not None:
         rmeta = RoutingMetadata(msg)
         outbound_rmeta = RoutingMetadata(outbound_hops_from)
         rmeta.set_outbound_hops(outbound_rmeta.get_hops())
     if is_reply_to_unroutable:
         rmeta = RoutingMetadata(msg)
         rmeta.set_unroutable_reply()
     return msg