Git Product home page Git Product logo

web-screenshot-to-slack-gas's Introduction

web-screenshot-to-slack-gas

Img

license standard-readme compliant PRs Welcome Actions Status

WebScreenshot with Google Apps script and API FLASH

This app is take screenshots of Web pages with GAS(Google Apps Script) and send images to Slack channel with Slack API.

Table of Contents

Background

I should get a screen capture of my website and paste it into Slack channels.

Because I wanted to do it easily, instead of setting up a dedicated server, I make it as FaaS using Google Apps Script (GAS).

And also, I want to use TypeScript because of a Test and Type lint, so using with clasp referenced by howdy39/gas-clasp-starter

Article

(Japanese)Google Apps Script(GAS)とAPI FLASHとSlackAPIをClaspとJestとGitHub Actionで調理して定期的にWebページのスクリーンショットを撮る

Install

Precondition

Create API FLASH Website Screenshot API AccessKey

This tool needs to API FLASH Access key because of taking of a Web page screenshot.

Visit https://apiflash.com and signup your account.

When create your account, visit Documentation page, check your access key, and note this!

Img

Create Slack API

Visit https://api.slack.com/apps?new_app=1 and Create New app

Img

Next, you add BOT features because need to Bot TOKEN

Img

And also, change Basic Information with API, install this app to your workspace.

Img

Additionally, Change your Slack bot Name.

Img

Finally, you can check your app's BOT users OAuth Access TOKEN, note this!!

Img

Create GAS Project

First you create a empty GAS project from Google Drive.

Img

When you create a GAS project, enter name and note script ID include the URL. (Red Underline)

Img

Next, enter your script ID to .clasp.json

{
  "scriptId": "FIXME: This value is your script ID",
  "rootDir": "dist"
}

Set environment variables with Script Properties

Set your API FLASH TOKEN, Slack API TOKEN, and some variables with Script Properties

Img

Img

Set variables below.

SLACK_TOKEN="Your Slack TOKEN Required"
API_FLASH_ACCESS_KEY="Your API FLASH Access Key Required"
WEB_PAGE_URL="Your Web pages URL, default value is Author's Blog"
SLACK_TITLE="Slack Message title, default value is Test"
WEB_PAGE_WIDTH="Screenshot Page Width, default is 1920"
WEB_PAGE_HEIGHT="Screenshot Page Height, default is 1080"
WEB_PAGE_CAPTURE_DELAY="This value is delay time between access your page and take a screenshot, default is 10 sec"
SLACK_CHANNEL="Slack channel which Send a screenshot, default is #general"

Install dependencies

Use npm, install dependencies.

npm install

Usage

Build App

Execute the command below, build script file using with webpack and create script files under dist directory.

npm run build

Push App

Before push app, you need to change GA user setting which enable API.

https://script.google.com/home/usersettings

Push App.

clasp login  # only first access
clasp push

Demos

Run main function , send Slack your web page screenshot.

Img

Test

If you modify this codes, run unit test with jest.

npm test

Also, this repo is integrated with GitHub Action.

So, Run CI test, if you write test.

GitHub Action

This repo use GitHub Action, Run tests, Build scripts and push scripts to GAS triggered by push to master branch.

If you want to upload script with GitHub Action, you will set your .clasprc.json on GitHub Action SECRET.

How to setup your clasprc.json

Before set your clasprc.json, run clasp login with your local PC.

clasp login

And you open ~/.clasprc.json with editor.

# If you use VSCode
code ~/.clasprc.json

Img

Copy it and paste another window, and replace " character to \" because of reading to one-line string on bash command.

Img

Copy it and paste your GitHub Action Secret (https://github.com/{your_name}/{your_repo}/settings/secrets)

Sectet name is CLASPRC_JSON and paste your clasprc.json.

Image

Congratulation! You can deploy to GitHub Action!

Contributing

See the contributing file!

PRs accepted.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © tubone.

web-screenshot-to-slack-gas's People

Contributors

tubone24 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

aplater

web-screenshot-to-slack-gas's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency tslint to v5.20.1
  • Update dependency tslint-plugin-prettier to v2.3.0
  • Update dependency typescript to v3.9.10
  • Update dependency webpack to v4.47.0
  • Update actions/checkout action to v4
  • Update actions/setup-node action to v4
  • Update dependency @types/google-apps-script to v1
  • Update dependency braces to v3
  • Update dependency dotenv to v16
  • Update dependency gas-webpack-plugin to v2
  • Update dependency prettier to v3
  • Update dependency rimraf to v5
  • Update dependency ts-loader to v9
  • Update dependency typescript to v5
  • Update dependency webpack to v5
  • Update dependency webpack-cli to v5
  • Update jest monorepo to v29 (major) (@types/jest, jest, ts-jest)
  • 🔐 Create all rate-limited PRs at once 🔐

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/nodejs.yml
  • actions/checkout v1
  • actions/setup-node v1
npm
package.json
  • dotenv ^8.1.0
  • fs 0.0.1-security
  • gas-local ^1.3.1
  • @types/google-apps-script 0.0.59
  • @types/jest 24.0.18
  • cpx 1.5.0
  • gas-webpack-plugin 1.0.2
  • jest 24.9.0
  • prettier 1.18.2
  • rimraf 3.0.0
  • ts-jest 24.0.2
  • ts-loader 6.0.4
  • tslint 5.19.0
  • tslint-config-prettier 1.18.0
  • tslint-plugin-prettier 2.0.1
  • typescript 3.5.3
  • webpack 4.39.3
  • webpack-cli 3.3.8
  • braces 2.3.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.