Giter Site home page Giter Site logo

js-tips-slack-bot's Introduction

JS Tips Slack Bot

Slack Bot implementation for sending the latest JS tips collected in https://github.com/loverajoel/jstips.

Install Node.js and npm

This is a Node.js app, so the first step is to be sure you have installed Node.js and npm:

  • OS X

Go to nodejs.org, Click install, and run through the install process.

  • Ubuntu

You can use the Node.js binary distributions

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs

More installation help at https://github.com/nodesource/distributions#deb

  • Windows

Go ahead to download the Windows binary at https://nodejs.org/en/download/

Clone this repo

Next step is to clone this repository using the following command:

git clone [email protected]:radibit/js-tips-slack-bot.git

and navigate to the cloned project folder:

cd js-tips-slack-bot

Installation

In the project folder run the command

npm install

in order to install locally the required dependencies.

Config

There are four config variables for this project:

  • GH_TOKEN - GitHub API token - can be generated from your GitHub settings panel
  • SLACK_TOKEN - Slack API Token - in order to create one visit Slack API settings
  • SLACK_GROUP - Target Slack group - specify the Slack group that will receive the messages
  • SLACK_POST_TO ( optional ) - Specify if the messages should be posted to a private group ( group ) which is the default option or a public channel ( channel )
  • DATABASE_URL - Heroku Postgres URL - provide URL in order to connect the app to a Postgres database. Once you installed the Heroku Postgres add-on you can find the required information on the connection settings panel

Test it locally

First you need to create .env file in the root folder of the project and list there the required config variables. You can use as a reference the .sample-env file.

After providing the required values for the config variables, you can run the app with the following command:

npm run start

If you want to end the started terminal process, you can do this using ctrl + c

Playing with the script you can adjust whether you want to send the js tip to a Slack group ( default ), channel or single user. More info about the exposed methods of the Slack's Real Time Messaging API can be found here

Heroku set up and deployment

It's fun to play locally with the app ๐Ÿ˜ƒ, but the real benefit of using it comes when we deploy it and set it up to automatically send us the new JS tips every day. So let's do this:

  1. Create an account and download Heroku https://toolbelt.heroku.com/

  2. Rename the .sample-env file to .env inside of the project folder and replace the placeholder variables with real tokens/values (see Config section)

  3. In the terminal, within the project folder, run the following command to create a new Heroku app:

heroku create

More help info how to use the Heroku CLI can be found on the Heroku DevCenter

  1. Commit and push the Heroku app:
git add -f .env

git commit -m "Added private tokens that I promise to never-ever-ever share with the public."

git push heroku master

With the last command you are actually deploying your app to Heroku and after that it will be already running live.

  1. You can find your new app listed in the Heroku dashboard

  2. Set up a database in order to store the latest JS tip and send a Slack message only when there is a new one.

You need to configure the Heroku Postgres add-on and create a table with a name js_tip and two columns - msg_id ( PRIMARY KEY ) and name ( varchar (250) )

  1. Enjoy ๐ŸŽ‰

js-tips-slack-bot's People

Contributors

loklaan avatar lukyth avatar radibit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

js-tips-slack-bot's Issues

The bot never start sending the message

Hey @radibit !

Right now I'm testing on my local machine and I can't send any message to Slack. Everything is fine, I can get the data from GitHub. It just won't send to Slack.

I found out that the reason is the open event is fired when websocket connection is open and ready to communicate (which is when a bot is successfully created). And a postMessageToGroup is bind to the open event.

bot.on( 'open', function() {
  ...
  bot.postMessageToGroup( process.env.SLACK_GROUP, jsTipMessage, params );
} );

which is inside ghget callback.

So, when a bot is successfully created, open event is fired, there's still nothing binding to that event. (There's still no response from GitHub so a callback still not fired). And the open event is never fired again because the bot is only created once.

I'm pretty sure it works just fine last night, but I don't really know why. (Maybe because Slackbot was created slower than GitHub response, I'm trying this on another network from last night.) So I'm wondering if you got the same problem as mine.

Permission denied(publickey)

Hi!
I got this message when i try to clone this repo: "Permission denied (publickey). fatal: could not read from remote repository".

Thanks for your answer

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.