Giter VIP home page Giter VIP logo

submit-this's Introduction

README

submit-this is a simple slack bot that can take a slack message, and construct a link (to a website of your choice) with query parameters derived from your message, and send you a slack message including the link. Designed to be useful for prefilling forms.

So, you could send the bot a message

@submitthis here is the data for submission

and the text "here is the data for submission" would be sent to the form. Alternatively the message

@submitthis http://an.intersting.website.com

would result in the opengraph data from the website (title, description, image) being sent to the form

Setup

Pre-requisites

To run this bot you will need a server which is publicly addressable, since slack needs to tell the bot when messages arrive. This is easy to work aroung for development scenarios using for instance services like ngrok.

Secondly, you'll need to make what slack calls 'an app' despite the name it doesn't involve coding. You'll just give your bot a name and some permissions to do things in the slack workspace you want to target. The overview of this process is

  • Create an 'app'
  • add 'Bots' under features and functionality
  • Install the app into your slack workspace
  • under features and functionality, got to permissions and add under 'Bot Token Scopes' these scopes 'app_mentions:read', 'channels:read', 'chat:write', 'groups:read'
  • again under features and functionality, go to 'event subscriptions' and under 'Subscribe to bot events' these events 'app_mentions' and 'member_joined_channel'
  • now re-install the app in your workspace, because adding the event subscriptions changed the permissions.

The best guide I can find for this is Developing Slack apps locally, most of which also applies to a production environment.

Install

Clone this repo

In your repo's directory, run yarn or npm install according to your preference.

Take a copy of .env.example called .env

Configure Slack

For development use, in the file .env customise the two slack environment variables with values for your app and workspace at api.slack.com. You will need the slack signing secret from 'basic information' and the 'Bot User OAuth Access Token' from the 'OAuth and permissions' page. In development (NODE_ENV=development or not defined) the app will read the variables from this file.

For production (NODE_ENV=production) you will need to set these environment variables yourself. E.g. heroku lets you define these variable via your dashboard.

Configure the bot

Configure more environment variables (differently in development and production as above)

  • PORT - the port your server will run on
  • SUBMIT_MESSAGE_TEMPLATE - to customise the complete message created by the bot.
  • SUBMIT_LINK_TEMPLATE - to customise the link created by the bot.

The message template in .env.example is a full example of how this could be used with airtable.com, using opengraph data obtained from a link in the message you send to the bot.

You may find this formatting guide useful ... most importantly, it shows how to craft a message with a url linked from alternative text, since this bot will likely be creating long links.

Start

  • Shell script: bin/bot
  • Node: node index or nodemon index

Design Decisions

Do not use RTM api it appears to be deprecated and use events api to capture messages instead.

Use 12 Factor principles. Application to node: The practical JS 12 factor application

Dependencies

ngrok

(useful for development)

Free service. Can install via homebrew. See this gist for help.

Getting started with ngrok

Reference

node-slack-sdk

submit-this's People

Contributors

baob avatar

Stargazers

 avatar

Watchers

 avatar  avatar

submit-this's Issues

parsing marked up link edgecase

New message parsing edge-case

2020-04-17T16:10:52.319939+00:00 app[web.1]: Processing submission: user U010GRNTFCG in channel C0107LWU917 says <@U011ZHHDW0Z> <https://europeanjournalism.fund/|https://europeanjournalism.fund/>
2020-04-17T16:10:52.320156+00:00 app[web.1]: ---- extracted data from message: {
2020-04-17T16:10:52.320157+00:00 app[web.1]:   message: '<https://europeanjournalism.fund/|https://europeanjournalism.fund/>',
2020-04-17T16:10:52.320157+00:00 app[web.1]:   atUser: '<@U010GRNTFCG>',
2020-04-17T16:10:52.320158+00:00 app[web.1]:   link: 'https://europeanjournalism.fund/|https://europeanjournalism.fund/'
2020-04-17T16:10:52.320158+00:00 app[web.1]: }

Doubled messages on Heroku

Problem with an events API based app running on heroku (free tier). Seems that something, perhaps the heroku infrastructure, perhaps slack itself, randomly sends 1-2 extra copies of ‘app_mention’ events.

Maybe slack saw timeouts or sluggish response from heroku and repeated the events.

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.