예제 #1
0
def get_inbox_partials(service_id):

    if 'inbound_sms' not in current_service['permissions']:
        abort(403)

    messages_to_show = list()
    inbound_messages = service_api_client.get_inbound_sms(service_id)

    for message in inbound_messages:
        if format_phone_number_human_readable(message['user_number']) not in {
                format_phone_number_human_readable(message['user_number'])
                for message in messages_to_show
        }:
            messages_to_show.append(message)

    if not inbound_messages:
        inbound_number = inbound_number_client.get_inbound_sms_number_for_service(
            service_id)['data']['number']
    else:
        inbound_number = None

    return {
        'messages':
        render_template(
            'views/dashboard/_inbox_messages.html',
            messages=messages_to_show,
            count_of_messages=len(inbound_messages),
            count_of_users=len(messages_to_show),
            inbound_number=inbound_number,
        )
    }
예제 #2
0
def get_sms_thread(service_id, user_number):

    for notification in sorted((
        notification_api_client.get_notifications_for_service(service_id,
                                                              to=user_number,
                                                              template_type='sms')['notifications'] +
        service_api_client.get_inbound_sms(service_id, user_number=user_number)['data']
    ), key=lambda notification: notification['created_at']):

        is_inbound = ('notify_number' in notification)
        redact_personalisation = not is_inbound and notification['template']['redact_personalisation']

        if redact_personalisation:
            notification['personalisation'] = {}

        yield {
            'inbound': is_inbound,
            'content': SMSPreviewTemplate(
                {
                    'content': (
                        notification['content'] if is_inbound else
                        notification['template']['content']
                    )
                },
                notification.get('personalisation'),
                downgrade_non_sms_characters=(not is_inbound),
                redact_missing_personalisation=redact_personalisation,
            ),
            'created_at': notification['created_at'],
            'status': notification.get('status'),
            'id': notification['id'],
        }
예제 #3
0
def inbox_download(service_id):
    return Response(
        Spreadsheet.from_rows([[
            'Phone number',
            'Message',
            'Received',
        ]] + [[
            message['user_number'],
            message['content'].lstrip(('=+-@')),
            format_datetime_numeric(message['created_at']),
        ] for message in service_api_client.get_inbound_sms(service_id)]
                              ).as_csv_data,
        mimetype='text/csv',
        headers={
            'Content-Disposition':
            'inline; filename="Received text messages {}.csv"'.format(
                format_date_numeric(datetime.utcnow().isoformat()))
        })