示例#1
0
    def slack(team_id=None, channel=None, params=None):


        target = Misc.array_pop(params,0)
        height = Misc.to_int(Misc.array_pop(params, 0))
        width  = Misc.to_int(Misc.array_pop(params, 0))

        if target is None: target = 'general'
        if width  is None: width = 800
        if height is None: height = 1000

        target_url = '/messages/{0}'.format(target)

        slack_message(":point_right: taking screenshot of slack channel: `{0}` with height `{1}` and width `{2}`".format(target, height,width), [], channel, team_id)

        payload = {'target' : target_url,
                   'channel': channel,
                   'team_id': team_id,
                   'width'  : width,
                   'height' : height}
        aws_lambda      = Lambda('osbot_browser.lambdas.slack_web')
        png_data        = aws_lambda.invoke(payload)

        browser_helper  = Browser_Lamdba_Helper()
        return browser_helper.send_png_data_to_slack(team_id, channel, target, png_data)
def run(event, context):
    load_dependency('pydot')
    channel = event.get('channel')
    data    = event.get('dot')

    #slack_message("in dot to svg: {0}".format(event), [], channel)
    log_to_elk("in dot to svg: {0}".format(event))

    import dot_parser

    try:
        (fd, tmp_file) = tempfile.mkstemp('dot)')
        dot_static     = '/tmp/lambdas-dependencies/pydot/dot_static'
        Process.run("chmod", ['+x', dot_static])
        data           = data.replace('&lt;', '<').replace('&gt;','>')  # this solved a really nasty bug caused by the fact that Slack will html encode the < and >

        # graph          = pydot.graph_from_dot_data(data).pop()
        # <from pydot>  use code below (instead of above) to get a better error message from dot parser
        graphparser = dot_parser.graph_definition()
        graphparser.parseWithTabs()
        tokens      = graphparser.parseString(data)
        graph       = list(tokens).pop()
        # </from pydot>
        graph.write_svg(tmp_file, prog=dot_static)
        svg_raw        = Files.contents(tmp_file)
        return base64.b64encode(svg_raw.encode()).decode()
    except Exception as error:
        slack_message("[dot_to_svg] Error: {0} ".format(error), [], channel)
        return None
示例#3
0
 def invoke(self, team_id=None, channel=None, params=None):
     if params is None: params = []
     attachments = []
     if len(params) == 0:
         (text, attachments) = self.help()
     else:
         original_params = list(params)
         command = params.pop(0)  # extract first element from the array
         if command in self.available_methods():
             method = getattr(self.target, command)
             try:
                 start = time()
                 result = method(team_id, channel, params)
                 if type(result).__name__ == 'tuple':
                     text, attachments = result
                 else:
                     text, attachments = result, []
                 if text is None and self._show_duration:
                     duration = time() - start
                     text = 'completed execution in `{0:.0f}` secs'.format(
                         duration)
             except Exception as error:
                 text = ':red_circle: Error processing params `{0}`: _{1}_'.format(
                     original_params, pprint.pformat(error))
                 log_to_elk(
                     "Error in Lambda_Graph.handle_lambda_event :{0}".
                     format(text),
                     level='error')
         else:
             (text, attachments) = self.help(
                 ':red_circle: command not found `{0}`\n\n'.format(command))
     if channel and text is not None:  # if there is a text value, then send it as a slack message
         slack_message(text, attachments, channel, team_id)
     return text, attachments
def run(event, context):
    team_id = 'T7F3AUXGV'
    channel = 'DDKUZTK6X'
    text = ":robot_face: In trigger_server_reload lambda function \n"

    payload = {
        "params": ["server", "reload"],
        "channel": channel,
        'team_id': team_id
    }
    result = Lambda('pbx_gs_python_utils.lambdas.gs.elastic_jira').invoke(
        payload)

    attachments = [{'text': result, 'color': 'good'}]

    slack_message(text, attachments, channel, team_id)

    result = Misc.json_format({'text': text})
    return {
        'headers': {
            'Content-Type': 'application/json'
        },
        "statusCode": 209,
        "body": result
    }
示例#5
0
 def screenshot(team_id=None, channel=None, params=[]):
     url          = params.pop(0).replace('<', '').replace('>', '')  # fix extra chars added by Slack
     delay        = Misc.to_int(Misc.array_pop(params,0))
     slack_message(":point_right: taking screenshot of url: {0}".format(url),[], channel,team_id)
     browser_helper = Browser_Lamdba_Helper().setup()
     png_data       = browser_helper.get_screenshot_png(url,full_page=True, delay=delay)
     return browser_helper.send_png_data_to_slack(team_id,channel,url, png_data)
 def test_render(self):
     self.api.set_text       ('this is the attachment text'            ) \
             .set_callback_id("button-test")                      \
             .add_button     ("name 1", "text 1", "type 3", "primary") \
             .add_button     ("name 2", "text 2", "type 3", "danger" )
     attachments = self.api.render()
     text = None  # 'main text'
     slack_message(text, attachments, 'DDKUZTK6X')
 def test_add_select_user_data_source(self):
     (self.api.set_text('here are the multiple data sources').
      set_callback_id("issue-suggestion").add_select_users(
          "user", "pick a user").add_select_channels(
              "user", "pick a channel").add_select_conversations(
                  "user", "pick a conversation").add_select_external(
                      "key", "pick an Key"))
     slack_message("", self.api.render(), 'DDKUZTK6X')
示例#8
0
    def gs_team(team_id=None, channel=None, params=None, headless=True):
        slack_message(
            ":point_right: Loading data from GS Team shared calendar", [],
            channel, team_id)

        calendar_data = Full_Calendar_Views._get_gcalendar().gs_team()
        return Full_Calendar_Views._show_google_calendar(
            calendar_data, team_id, channel)
示例#9
0
    def test__create_button_to_test_dialog(self):
        #Lambda('gs.jira_dialog').update_with_src()

        self.api_attach.set_text       ('Click on button below to test dialog'    ) \
                       .set_callback_id("button-dialog-test"                      ) \
                       .add_button     ("button", "open dialog", "open", "primary")
        attachments = self.api_attach.render()
        slack_message("", attachments, 'DDKUZTK6X')
    def test_select(self):
        text = "...testing select attachment"
        (self.api.set_text('this is the attachment text').set_callback_id(
            "button-test").set_color("#0055AA").add_button(
                "name 1", "text 1", "type 3", "primary").add_button(
                    "name 2", "text 2", "type 3",
                    "danger").add_select("name", "pick a value", [
                        ("text 1", "value-1"), ("text 2", "value-2")
                    ]).add_select_users("user", "pick a user"))

        attachments = self.api.render()
        slack_message(text, attachments, 'DDKUZTK6X')
示例#11
0
    def test__create_button_to_test_dialog(self):
        self.test_lambda_update()
        from pbx_gs_python_utils.utils.Lambdas_Helpers import slack_message
        from pbx_gs_python_utils.utils.slack.API_Slack_Attachment import API_Slack_Attachment
        self.api_attach = API_Slack_Attachment()
        self.api_attach.set_text       ('Click on button below to test dialog'          )   \
                       .set_callback_id("button-dialog-test"                            )   \
                       .add_button     ("button 1", "click-me-1", "open 1", "primary"   )   \
                       .add_button     ("button 2", "click-me-2", "open 2", "primary"   )
        attachments = self.api_attach.render()

        slack_message("one message", attachments, 'DDKUZTK6X')
 def view(team_id=None, channel=None, params=None):
     name = " ".join(params)
     aws_lambda = Lambda('oss_bot.lambdas.git_lambda')
     payload = {'action': 'participant_url',
                'name'  : name,
                'commit': False}
     result = aws_lambda.invoke(payload)
     if result.get('status') == 'ok':
         path = result.get('data')
         send_screenshot_to_slack(path,channel,[1200])
     else:
         slack_message(":red_circle: Sorry, couldn't find url for `{0}`".format(name),[],channel)
         return ":red_circle: Sorry, couldn't find url for `{0}`".format(name)
    def test_deploy_lambda_functions(self):
        targets = [
            'osbot_browser.lambdas.lambda_browser',
        ]
        result = ""
        for target in targets:
            Deploy(target).deploy()
            result += " • {0}\n".format(target)

        text = ":hotsprings: [osbot-gsuite] updated lambda functions"
        attachments = [{'text': result, 'color': 'good'}]
        slack_message(text, attachments)  # gs-bot-tests
        Dev.pprint(text, attachments)
示例#14
0
    def render(team_id, channel, params):

        if params:
            target = params.pop(0)
            delay  = Misc.to_int(Misc.array_pop(params,0))
            if len(params) == 4:
                clip = {'x': int(params[0]), 'y': int(params[1]), 'width': int(params[2]), 'height': int(params[3])}
            else:
                clip = None
        else:
            return None

        slack_message(":point_right: rendering file `{0}`".format(target), [], channel, team_id)
        return Browser_Lamdba_Helper().setup().render_file(team_id, channel, target,clip=clip, delay=delay)
 def today(*event):
     channel = event[1]
     slack_message(
         ":mag_right: Ok, fetching the latest version of today's schedule :mag:",
         [], channel)
     params = ['oss_today']
     slack_event = {'channel': event[1]}
     from osbot_aws.apis.Lambda import Lambda
     Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({
         'params':
         params,
         'data':
         slack_event
     }), []
    def mine(slack_id, channel, params):
        slack_message(
            ":mag_right: Ok, fetching scheadule for <@{0}>".format(slack_id),
            [], channel)
        name = API_OSS_Slack().slack_id_to_slack_full_name(slack_id)

        text = 'participant view {0}'.format(name)
        from osbot_aws.apis.Lambda import Lambda
        aws_lambda = Lambda('oss_bot.lambdas.oss_bot')
        aws_lambda.invoke_async(
            {'event': {
                'type': 'message',
                'text': text,
                "channel": channel
            }})
示例#17
0
    def default(team_id=None,
                channel=None,
                params=None,
                no_render=False,
                headless=True):

        load_dependencies(['syncer', 'requests'])
        from osbot_browser.view_helpers.VivaGraph_Js import VivaGraph_Js

        graph_name = params.pop(0)
        vivagraph_js = VivaGraph_Js(headless=headless)  # will start browser

        graph_data = vivagraph_js.get_graph_data(graph_name)
        #
        vivagraph_js.load_page(False)
        if graph_data:
            edges = graph_data.get('edges')
            nodes = []
            for key, issue in graph_data.get('nodes').items():
                if issue and issue.get("Image Url"):
                    (label, img_size, img_url) = (key, 20,
                                                  issue.get("Image Url"))
                else:
                    (label, img_size,
                     img_url) = vivagraph_js.resolve_icon_from_issue_type(
                         issue, key)
                node = {
                    'key': key,
                    'label': label,
                    'img_url': img_url,
                    'img_size': img_size,
                    #'issue_type' : issue.get('Issue Type'),
                    #'summary'    : issue.get('Summary')
                }
                nodes.append(node)
            slack_message(
                ":point_right: Rendering `{0}` using VivaGraph JS engine (`{1}` nodes and `{2}` edges)"
                .format(graph_name, len(nodes),
                        len(edges)), [], channel, team_id)

            if no_render is True:
                return graph_name, nodes, edges, graph_data, vivagraph_js

            options = {}
            return vivagraph_js.create_graph_and_send_screenshot_to_slack(
                nodes, edges, options, team_id, channel)
示例#18
0
 def mindmap(slack_event, params=None):
     channel = slack_event.get('channel')
     team_id = slack_event.get('team_id')
     if len(params) < 1:
         text = ':red_circle: Hi, for the `mindmap` command, you need to provide an `graph_name`'
         slack_message(text, [], channel, team_id)
         return None, None
     graph_name = params.pop(0)
     graph_params = ['go_js', graph_name, 'mindmap']
     graph_params.extend(params)
     Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({
         "params": graph_params,
         'data': {
             'team_id': team_id,
             'channel': channel
         }
     })
     return None, None
    def reload_jira_index__it_Assets(self):           # need to do also do this for the SEC project
        index = 'it_assets'
        self.elastic.index = index
        query = {  "query": { "match_all": {} } }
        result     = self.elastic.delete_using_query(query)     # delete all items

        slack_message(':point_right: starting reload_jira_index__it_Assets', [], 'DDKUZTK6X', 'T7F3AUXGV')

        ia_issues    = self.send_data_from_project('IA')
        tm_issues    = self.send_data_from_project('TM')
        gdpr_issues  = self.send_data_from_project('GDPR')
        gsp_issues   = self.send_data_from_project('GSP')
        gsokr_issues = self.send_data_from_project('GSOKR')
        rt_issues    = self.send_data_from_project('RT')
        fix_issues   = self.send_data_from_project('FIX')
        sc_issues    = self.send_data_from_project('SC')
        gssp_issues  = self.send_data_from_project('GSSP')
        sl_issues    = self.send_data_from_project('SL')
        gsos_issues  = self.send_data_from_project('GSOS')
        gscs_issues  = self.send_data_from_project('GSCS')
        gsbot_issues = self.send_data_from_project('GSBOT')
        gsed_issues  = self.send_data_from_project('GSED')

        stats = { "stats": {
                            "index"             : index             ,
                            "delete_issues"     : result['deleted'] ,
                            "ia_issues_added"   : ia_issues         ,
                            "tm_issues_added"   : tm_issues         ,
                            "gdpr_issues_added" : gdpr_issues       ,
                            "gsp_issues_added"  : gsp_issues        ,
                            "gskr_issues_added" : gsokr_issues      ,
                            "rt_issues_added"   : rt_issues         ,
                            "fix_issues_added"  : fix_issues        ,
                            "sc_issues"         : sc_issues         ,
                            "gssp_issues"       : gssp_issues       ,
                            "sl_issues"         : sl_issues         ,
                            "gsos_issues"       : gsos_issues       ,
                            "gscs_issues"       : gscs_issues       ,
                            "gsbot_issues"      : gsbot_issues      ,
                            "gsed_issues"       : gsed_issues
                          }}
        Dev.pprint(stats)
        slack_message(json.dumps(stats), [], 'DDKUZTK6X','T7F3AUXGV')
        return stats
示例#20
0
    def log_message(self):
        graph_name = 'graph_BEY'
        folder = '1o-kpQ9sLzo0_wE13XcmnUuH7GNsHpdbp'
        domain = 'photobox.com'

        print('******* In Update_Sheet **** [Start]')
        message = os.environ['message']
        channel = 'DDKUZTK6X'
        team_id = 'T7F3AUXGV'
        slack_message(message, [], channel, team_id)

        file_id = '1_Bwz6z34wALFGb1ILUXG8CtF1-Km6F9_sGXnAu4gewY'
        gsuite_secret_id = 'gsuite_gsbot_user'
        sheets_sync = API_Jira_Sheets_Sync(file_id=file_id,
                                           gsuite_secret_id=gsuite_secret_id)
        result = sheets_sync.load_data_from_jira()
        Dev.pprint(result)

        print('******* In Sync_Sheet **** [End]')
def run(event, context):
    team_id = 'T7F3AUXGV'
    channel = 'DDKUZTK6X'
    text = "in API Gateway test..."
    attachments = [{
        'text': "{0}".format(Misc.json_format(event)),
        'color': 'good'
    }]
    #attachments = [{'text': "{0}".format(event), 'color': 'good'}]

    slack_message(text, attachments, channel, team_id)

    result = Misc.json_format({'text': text})
    return {
        'headers': {
            'Content-Type': 'application/json'
        },
        "statusCode": 209,
        "body": result
    }
示例#22
0
def run(event, context):
    action    = event.get('action'   )
    #name      = event.get('name'     )
    field     = event.get('field'    )
    value     = event.get('value'    )
    user      = event.get('user'     )
    commit    = event.get('commit'   )
    channel   = event.get('channel'  )

    if commit is None: commit = True

    if user is None:
        user = '******'

    if action:
        load_dependency('lambda-git' )
        load_dependency('frontmatter')


        from oss_bot.api_in_lambda.OSS_Hugo   import OSS_Hugo
        try:
            oss_hugo = OSS_Hugo().setup()
            method   = getattr(oss_hugo,action)

            result = method(event) #name, field, value)
            if commit:
                commit_message = 'Lambda change, requested by user: {0} \n' \
                                 ' - action: {1} \n'             \
                                 ' - field: {2}  \n'             \
                                 ' - value: {3}'                 .format(user, action, field, value)
                oss_hugo.git_commit_and_push(commit_message)
                if channel:
                    slack_message("Changes pushed to GitHub", [], channel)
                return {'status': 'ok'}
            else:
                if channel:
                    slack_message("{0}".format(result), [], channel)
            return {'status': 'ok', 'data': result}
        except Exception as error:
            return {'status': 'error', 'data': "{0}".format(error)}
    return {'status': 'error', 'data': 'error occurred when updating data'}
def run(event, context):
    team_id = 'T7F3AUXGV'
    channel = 'DDKUZTK6X'
    querystring = event.get('queryStringParameters')
    if querystring and querystring.get('file_id'):
        file_id = querystring.get('file_id')
        if querystring.get('action') == 'diff':
            payload = {
                "params": ["diff_sheet", file_id],
                "channel": "DDKUZTK6X",
                'team_id': 'T7F3AUXGV'
            }
        elif querystring.get('action') == 'sync':
            payload = {
                "params": ["sync_sheet", file_id],
                "channel": "DDKUZTK6X",
                'team_id': 'T7F3AUXGV'
            }
        else:
            payload = {
                "params": ["load_sheet", file_id],
                "channel": "DDKUZTK6X",
                'team_id': 'T7F3AUXGV'
            }
        Lambda('pbx_gs_python_utils.lambdas.gs.elastic_jira').invoke(payload)
        text = ":point_right: [trigger_sync_jira_sheets] completed workflow for file_id: {0} , see channel {1} for more details".format(
            file_id, channel)
        status_code = 201
    else:
        text = "Error: file_id value not provided"
        status_code = 501

    slack_message(text, [], channel, team_id)

    return {
        'headers': {
            'Content-Type': 'application/json'
        },
        "statusCode": status_code,
        "body": Misc.json_format({'text': text})
    }
示例#24
0
 def send_graph_name_to_slack(self, team_id, channel):
     from pbx_gs_python_utils.utils.Lambdas_Helpers import slack_message
     slack_message(
         ":point_right: Created graph `{0}` from jira key `{1}`".format(
             self.graph_name, self.jira_key), [], channel, team_id)
     return self
示例#25
0
def log_message(message):
    slack_message(message, [], 'GDL2EC3EE', 'T7F3AUXGV')
 def log_message(message):
     slack_message(':point_right: {0}'.format(message),[],channel,team_id)
 def log_error(message):
     slack_message(':red_circle: {0}'.format(message),[],channel,team_id)
 def log_status(self,message):
     if self.team_id and self.channel:
         slack_message(message, [], self.channel, self.team_id)
示例#29
0
 def test_slack_message(self):
     result = slack_message('an message')
     Dev.pprint(result)