コード例 #1
0
    def setup_class(cls):
        # get admin
        cls.admin = Admin.all()[1]

        # get user
        timestamp = get_timestamp()
        cls.user = get_or_create_user(timestamp)
        cls.email = cls.user.email

        # send user message
        message_data = {
            'from': {
                'type': "user",
                'id': cls.user.id
            },
            'body': "Hey"
        }
        cls.user_message = Message.create(**message_data)

        conversations = Conversation.find_all()
        user_init_conv = conversations[0]
        # send admin reply
        cls.admin_conv = user_init_conv.reply(type='admin',
                                              admin_id=cls.admin.id,
                                              message_type='comment',
                                              body='There')
コード例 #2
0
def validate_contact_info(value):
    Intercom.app_id = settings.INTERCOM_APP_ID
    Intercom.app_api_key = settings.INTERCOM_API_KEY
    value_type = value.get('type', None)
    user_id = value.get('user_id', None)
    passed_id = value.get('id', None)
    if value_type != "user" and value_type != "admin":
        raise serializers.ValidationError("The only valid values for 'type' "
                                          "are 'user' and 'admin'")
    if value_type == "user" and user_id is None:
        raise serializers.ValidationError("Must provide the 'user_id' key "
                                          "when attempting to send a message "
                                          "to or from a user")
    if value_type == "admin":
        if passed_id is None:
            raise serializers.ValidationError("Must provide the 'id' key when "
                                              "attempting to send a message "
                                              "to or from an admin")

        if str(passed_id) not in [str(admin.id) for admin in Admin.all()]:
            raise serializers.ValidationError("%s is not a valid admin ID" %
                                              passed_id)

    try:
        # Use nodes here rather than get helper so we don't accidentally
        # store this in the cache or look at bad cache to determine if
        # event can be stored or not.
        Pleb.nodes.get(username=user_id)
    except (Pleb.DoesNotExist, DoesNotExist):
        if value_type != 'admin':
            raise serializers.ValidationError("Profile %s Does Not Exist" %
                                              user_id)

    return value
コード例 #3
0
    def setup_class(cls):
        # get admin
        cls.admin = Admin.all()[1]

        # get user
        timestamp = get_timestamp()
        cls.user = get_or_create_user(timestamp)
        cls.email = cls.user.email

        # send user message
        message_data = {
            'from': {
                'type': "user",
                'id': cls.user.id
            },
            'body': "Hey"
        }
        cls.user_message = Message.create(**message_data)

        conversations = Conversation.find_all()
        user_init_conv = conversations[0]
        # send admin reply
        cls.admin_conv = user_init_conv.reply(
            type='admin', admin_id=cls.admin.id,
            message_type='comment', body='There')
コード例 #4
0
ファイル: webhook.py プロジェクト: adamtrinity/IntercomBot
    def _assign_assignee(self, conversation, assignee_id):
        """
        @param conversation - Intercom Conversation class object
        """
        LOGGER.debug(
            "Assigning assignee {a_id} for conversation {c_id}".format(
                a_id=assignee_id, c_id=conversation.id))

        user = Admin.find(id=assignee_id)
        mention = MENTION_TEMPLATE.format(intercom_app_id=Intercom.app_id,
                                          user_id=user.id,
                                          username=user.name)
        conversation.reply(
            type='admin',
            id=SUGGESTOR_ID,
            message_type='note',
            body="Autoassigned to {mention}".format(mention=mention))
        conversation.assign(assignee_id=assignee_id, admin_id=assignee_id)
コード例 #5
0
ファイル: webhook.py プロジェクト: adamtrinity/IntercomBot
    def _suggest_assignee(self, conversation, assignee_id):
        """
        @param conversation - Intercom Conversation class object
        """
        LOGGER.debug(
            "Suggesting assignee {a_id} for conversation {c_id}".format(
                a_id=assignee_id, c_id=conversation.id))

        if conversation.assignee.id == assignee_id:
            # don't suggest the user that is already assigned
            return

        user = Admin.find(id=assignee_id)
        mention = MENTION_TEMPLATE.format(intercom_app_id=Intercom.app_id,
                                          user_id=user.id,
                                          username=user.name)
        conversation.reply(
            type='admin',
            id=SUGGESTOR_ID,
            message_type='note',
            body="This seems fit for {mention}".format(mention=mention))
コード例 #6
0
 def test(self):
     # Iterate over all admins
     for admin in Admin.all():
         self.assertIsNotNone(admin.id)
         self.assertIsNotNone(admin.email)
コード例 #7
0
ファイル: test_admin.py プロジェクト: buremba/rakam-tasks
 def it_returns_a_collection_proxy_for_all_without_making_any_requests(self):  # noqa
     # prove a call to send_request_to_path will raise an error
     with assert_raises(AssertionError):
         send_request()
     all = Admin.all()
     self.assertIsInstance(all, CollectionProxy)
コード例 #8
0
def stuff_with_all_convos():
    for admin in Admin.all():
        # need to add unassigned since there will be a lot of those
        for convo in Conversation.find_all(type='admin', id=admin.id):
            print convo.id