Example #1
0
def fetch_elvanto_groups(force=False):
    """Fetch all Elvanto groups."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    if force or config.sync_elvanto:
        from elvanto.models import ElvantoGroup
        ElvantoGroup.fetch_all_groups()
Example #2
0
def pull_elvanto_groups(force=False):
    """Pull all the Elvanto groups that are set to sync."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    if force or config.sync_elvanto:
        from elvanto.models import ElvantoGroup
        ElvantoGroup.pull_all_groups()
Example #3
0
def pull_elvanto_groups(force=False):
    """Pull all the Elvanto groups that are set to sync."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    if force or config.sync_elvanto:
        from elvanto.models import ElvantoGroup
        ElvantoGroup.pull_all_groups()
Example #4
0
def get_person_or_ask_for_name(from_, sms_body, keyword_obj):
    try:
        person_from = Recipient.objects.get(number=from_)
    except Recipient.DoesNotExist:
        person_from = Recipient.objects.create(number=from_,
                                               first_name='Unknown',
                                               last_name='Person')
        person_from.save()
        if keyword_obj == "name":
            pass
        else:
            from apostello.models import SiteConfiguration
            config = SiteConfiguration.get_solo()
            if not config.disable_all_replies:
                person_from.send_message(
                    content=fetch_default_reply('auto_name_request'),
                    sent_by="auto name request"
                )
                notify_office_mail.delay(
                    '[Apostello] Unknown Contact!',
                    'SMS: {0}\nFrom: {1}\n\n\nThis person is unknown and has been asked for their name.'.format(
                        sms_body,
                        from_
                    ),
                )

    return person_from
Example #5
0
def fetch_elvanto_groups(force=False):
    """Fetch all Elvanto groups."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    if force or config.sync_elvanto:
        from elvanto.models import ElvantoGroup
        ElvantoGroup.fetch_all_groups()
Example #6
0
def sms(request):
    """
    Handles all incoming messages from Twilio.
    This is the start of the message processing pipeline.
    """
    r = twiml.Response()
    params = request.POST
    from_ = params['From']
    sms_body = params['Body'].strip()
    keyword_obj = Keyword.match(sms_body)
    # get person object and optionally ask for their name
    person_from = get_person_or_ask_for_name(from_, sms_body, keyword_obj)
    log_msg_in.delay(params, timezone.now(), person_from.pk)
    post_to_slack.delay(
        "{0}\nFrom: {1}\n(matched: {2})".format(
            sms_body, str(person_from), str(keyword_obj)
        )
    )

    reply = reply_to_incoming(person_from, from_, sms_body, keyword_obj)

    config = SiteConfiguration.get_solo()
    if not config.disable_all_replies:
        r.message(reply)

    return r
Example #7
0
def post_to_slack(msg):
    from apostello.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    url = config.slack_url
    if url:
        data = {'text': msg, 'username': '******', "icon_emoji": ":speech_balloon:"}
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        requests.post(url, data=json.dumps(data), headers=headers)
Example #8
0
def notify_office_mail(subject, body):
    from apostello.models import SiteConfiguration
    to_ = SiteConfiguration.get_solo().office_email
    send_async_mail(
        subject,
        body,
        to_
    )
Example #9
0
def less_than_sms_char_limit(value):
    from apostello.models import SiteConfiguration
    s = SiteConfiguration.get_solo()
    sms_char_lim = s.sms_char_limit - settings.MAX_NAME_LENGTH + len('%name%')
    if len(value) > sms_char_lim:
        raise ValidationError(
            'You have exceed the maximum char limit of {0}.'.format(
                sms_char_lim
            )
        )
Example #10
0
def post_to_slack(attachments):
    """Post message to slack webhook."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    url = config.slack_url
    if url:
        data = {
            'username': '******',
            'icon_emoji': ':speech_balloon:',
            'attachments': attachments
        }
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        r = requests.post(url, data=json.dumps(data), headers=headers)
        print(r)
Example #11
0
def post_to_slack(attachments):
    """Post message to slack webhook."""
    from site_config.models import SiteConfiguration
    config = SiteConfiguration.get_solo()
    url = config.slack_url
    if url:
        data = {
            'username': '******',
            'icon_emoji': ':speech_balloon:',
            'attachments': attachments
        }
        headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
        r = requests.post(url, data=json.dumps(data), headers=headers)
        print(r)
Example #12
0
def send_async_mail(subject, body, to):
    from apostello.models import SiteConfiguration
    from_ = SiteConfiguration.get_solo().from_email
    send_mail(subject, body, from_, to)
Example #13
0
def notify_office_mail(subject, body):
    """Send email to office."""
    from apostello.models import SiteConfiguration
    to_ = SiteConfiguration.get_solo().office_email
    send_async_mail(subject, body, [to_])