Пример #1
0
    def _fetch_users():
        for user in IntercomUser.iter_and_sync(project):
            if not user.is_useful_domain:
                logger.info('Unuseful domain: %s. Skip.', user.domain)
                continue

            yield user.transformed_email
Пример #2
0
def handle_intercom_hooks(internal_secret):
    project = Project.query.filter(
        Project.intercom_webhooks_internal_secret == internal_secret).first()

    if not project:
        raise abort(400)

    user = request.json['data']['item']

    intercom_user = IntercomUser.get_or_create(
        project,
        user['user_id'],
        user['email'],
        commit=True)

    # TODO: put email into the stack (or use special flag in IntercomUser)
    # and make an actual call of the fetch_and_update_information e.g.
    # every hour  with all of these emails.

    if intercom_user.is_useful_domain:
        fetch_and_update_information.delay([intercom_user.transformed_email],
                                           project.id)

    return json.dumps({'status': 'ok'})