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 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 run(event, context): load_dependencies('syncer,requests,pyppeteer,websocket-client') from osbot_aws.helpers.Lambda_Helpers import slack_message from osbot_browser.browser.sites.Web_Slack import Web_Slack from osbot_browser.browser.Browser_Lamdba_Helper import Browser_Lamdba_Helper target = event.get('target') channel = event.get('channel') team_id = event.get('team_id') width = event.get('width') height = event.get('height') scroll_by = event.get('scroll_by') delay = event.get('delay') try: if width is None: width = 1200 if height is None: height = 1000 web_slack = Web_Slack(team_id=team_id).setup() web_slack.login() web_slack.page.width(width, height) if target: web_slack.open(target) if scroll_by: web_slack.scroll_messages_by(scroll_by) if delay: web_slack.wait(delay) web_slack.fix_ui_for_screenshot() png_data = web_slack.screenshot() slack_message( ':information_source: got screenshot with size `{0}` | :point_right: sending screeenshot to slack channel `{1}`' .format(len(png_data), channel), [], channel=channel, team_id=team_id) browser_helper = Browser_Lamdba_Helper() return browser_helper.send_png_data_to_slack(team_id, channel, target, png_data) except Exception as error: return slack_message( ':red_circle: Error in `slack_web` lambda: {0}'.format(error), [], channel=channel, team_id=team_id)
def screenshot(team_id=None, channel=None, params=None): params = params or [] try: url = None if len(params) > 0: url = params.pop(0).replace('<', '') \ .replace('>', '') # fix extra chars added by Slack and the u00a0 unicode char. if url == '_': # special mode to not render url = None else: message = ":point_right: taking screenshot of url: {0}".format( url) if url is None: message = ':point_right: no url provided, so showing what is currently on the browser' width = to_int(Misc.array_pop(params, 0)) height = to_int(Misc.array_pop(params, 0)) delay = to_int(Misc.array_pop(params, 0)) if width: message += ", with width `{0}`".format(width) if height: message += ", with height `{0}` (min height)".format(height) if delay: message += ", with delay of `{0}` seconds".format(delay) slack_message(message, [], channel) browser_helper = Browser_Lamdba_Helper().setup() if width: browser_helper.api_browser.sync__browser_width(width, height) png_data = browser_helper.get_screenshot_png(url, full_page=True, delay=delay) slack_message( f':point_right: got screenshot of size {len(png_data)}, sending it to Slack...', [], channel) return browser_helper.send_png_data_to_slack( team_id, channel, url, png_data) except Exception as error: import traceback message = f':red_circle: Browser Error: {error} \n {traceback.format_exc()}' #message = f':red_circle: Browser Error: {error}' return slack_message(message, [], channel, team_id)