Example #1
0
def beacon(event, **kwargs):
    """Beacon geo-ip location handler for Slack webhook events

    Creates a homing beacon URL for the user good for 5 minutes
    When the beacon URL is clicked, the IP address will be geo-located and shared to Slack
    """
    text = kwargs.get('text')
    command = kwargs.get('command')
    args = kwargs.get('args')

    if command == 'beacon':
        from htk.lib.slack.beacon.utils import create_slack_beacon_url
        beacon_url = create_slack_beacon_url(event)
        if beacon_url:
            beacon_text = 'Open this URL to trigger the beacon: %s' % beacon_url
            user_channel = '@%s' % event['user_name']
            webhook_url = event['webhook_settings']['slack_webhook_url']
            webhook_call(
                webhook_url=webhook_url,
                text=beacon_text,
                channel=user_channel,
                unfurl_links=False,
                unfurl_media=False,
            )
            slack_text = 'Homing beacon message deployed to <%s>.' % user_channel
        else:
            slack_text = 'Slack homing beacon not set up correctly.'
    else:
        slack_text = 'Illegal command.'

    payload = {
        'text' : slack_text,
    }
    return payload
Example #2
0
def beacon(event, **kwargs):
    """Beacon geo-ip location handler for Slack webhook events

    Creates a homing beacon URL for the user good for 5 minutes
    When the beacon URL is clicked, the IP address will be geo-located and shared to Slack
    """
    text = kwargs.get('text')
    command = kwargs.get('command')
    args = kwargs.get('args')

    if command == 'beacon':
        from htk.lib.slack.beacon.utils import create_slack_beacon_url
        beacon_url = create_slack_beacon_url(event)
        if beacon_url:
            beacon_text = 'Open this URL to trigger the beacon: %s' % beacon_url
            user_channel = '@%s' % event['user_name']
            webhook_url = event['webhook_settings']['slack_webhook_url']
            webhook_call(
                webhook_url=webhook_url,
                text=beacon_text,
                channel=user_channel,
                unfurl_links=False,
                unfurl_media=False,
            )
            slack_text = 'Homing beacon message deployed to <%s>.' % user_channel
        else:
            slack_text = 'Slack homing beacon not set up correctly.'
    else:
        slack_text = 'Illegal command.'

    payload = {
        'text': slack_text,
    }
    return payload
Example #3
0
def render_url_to_pdf_response(url):
    from htk.lib.slack.utils import webhook_call
    webhook_call(text=url)
    import pdfkit
    pdf = pdfkit.from_url(url, False, options=WKHTMLTOPDF_OPTIONS)
    if pdf:
        response = HttpResponse(pdf, content_type='application/pdf')
    else:
        response = HttpResponseServerError('Error generating PDF file')
    return response
Example #4
0
def render_url_to_pdf_response(url):
    from htk.lib.slack.utils import webhook_call
    webhook_call(text=url)
    import pdfkit
    pdf = pdfkit.from_url(url, False, options=WKHTMLTOPDF_OPTIONS)
    if pdf:
        response = HttpResponse(pdf, content_type='application/pdf')
    else:
        response = HttpResponseServerError('Error generating PDF file')
    return response
Example #5
0
 def remind_pull_requests(self):
     markdown_content, attachments = self.pull_request_reminder()
     from htk.utils.text.converters import markdown2slack
     slack_text = markdown2slack(markdown_content)
     from htk.lib.slack.utils import webhook_call
     webhook_call(webhook_url=self.slack_webhook_url,
                  channel=self.slack_channel,
                  text=slack_text,
                  attachments=attachments,
                  username='******',
                  icon_emoji=':octocat:',
                  unfurl_links=False)
Example #6
0
 def remind_pull_requests(self):
     markdown_content, attachments = self.pull_request_reminder()
     from htk.utils.text.converters import markdown2slack
     slack_text = markdown2slack(markdown_content)
     from htk.lib.slack.utils import webhook_call
     webhook_call(
         webhook_url=self.slack_webhook_url,
         channel=self.slack_channel,
         text=slack_text,
         attachments=attachments,
         username='******',
         icon_emoji=':octocat:',
         unfurl_links=False
     )
Example #7
0
def slack_beacon_view(request):
    """Receiver for Slack homing beacon
    """

    beacon_key = request.GET.get('k')
    from htk.lib.slack.beacon.cachekeys import SlackBeaconCache
    c = SlackBeaconCache(prekey=beacon_key)
    beacon = c.get()
    ip = extract_request_ip(request)
    if beacon:
        from htk.lib.slack.messages import slack_message_geoip
        slack_text = slack_message_geoip(ip, beacon['user_name'])
        from htk.lib.slack.utils import webhook_call
        webhook_call(
            webhook_url=beacon['slack_webhook_url'],
            channel=beacon['channel_name'],
            text=slack_text,
        )
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Example #8
0
def slack_beacon_view(request):
    """Receiver for Slack homing beacon
    """

    beacon_key = request.GET.get('k')
    from htk.lib.slack.beacon.cachekeys import SlackBeaconCache
    c = SlackBeaconCache(prekey=beacon_key)
    beacon = c.get()
    ip = extract_request_ip(request)
    if beacon:
        from htk.lib.slack.messages import slack_message_geoip
        slack_text = slack_message_geoip(ip, beacon['user_name'])
        from htk.lib.slack.utils import webhook_call
        webhook_call(
            webhook_url=beacon['slack_webhook_url'],
            channel=beacon['channel_name'],
            text=slack_text,
        )
        response = json_response_okay()
    else:
        response = json_response_error()
    return response
Example #9
0
def handle_message_event(event):
    incoming_number = event['To']
    user = get_plivo_number_owner(incoming_number)
    if user:
        slack_webhook_url = user.profile.get_attribute('plivo_slack_webhook_url')
        message = u'Plivo Message from *%(From)s* (%(Type)s; %(MessageUUID)s)\n>>> %(Text)s' % event
        from htk.lib.slack.utils import webhook_call
        webhook_response = webhook_call(
            webhook_url=slack_webhook_url,
            text=message
        )
        result = True
    else:
        result = False
    return result
Example #10
0
def handle_message_event(event):
    """Handles a Plivo message event
    """
    incoming_number = event['To']
    user = get_plivo_number_owner(incoming_number)
    if user:
        slack_webhook_url = user.profile.get_attribute('plivo_slack_webhook_url')
        message_format = user.profile.get_attribute('plivo_slack_message_format') or PLIVO_SLACK_DEFAULT_MESSAGE_FORMAT
        message = message_format % event
        from htk.lib.slack.utils import webhook_call
        webhook_response = webhook_call(
            webhook_url=slack_webhook_url,
            text=message
        )
        result = True
    else:
        result = False
    return result
Example #11
0
def handle_message_event(event):
    """Handles a Plivo message event
    """
    incoming_number = event['To']
    user = get_plivo_number_owner(incoming_number)
    if user:
        slack_webhook_url = user.profile.get_attribute(
            'plivo_slack_webhook_url')
        message_format = user.profile.get_attribute(
            'plivo_slack_message_format') or PLIVO_SLACK_DEFAULT_MESSAGE_FORMAT
        message = message_format % event
        from htk.lib.slack.utils import webhook_call
        webhook_response = webhook_call(webhook_url=slack_webhook_url,
                                        text=message)
        result = True
    else:
        result = False
    return result
Example #12
0
def slack_debug(message):
    from htk.lib.slack.utils import webhook_call
    channel = htk_setting('HTK_SLACK_DEBUG_CHANNEL')
    webhook_call(text=message, channel=channel)
Example #13
0
def slack_debug(message):
    from htk.lib.slack.utils import webhook_call
    channel = htk_setting('HTK_SLACK_DEBUG_CHANNEL')
    webhook_call(text=message, channel=channel)