Slackbot Using Javascript


Simple Slack Bot using JavaScript

*This post is not a tutorial, it’s intended for my personal note only.

Github

Basic knowledge about Slack Bot

  1. Basic use
    • Sample, a simple bot Reminder
    • /remind me Enjoy your life in Everyday/remind me Enjoy your life in Everyday2.sample2
  2. Slack API
    1. Create slack app3.createApp.png
    2. Manage slack app Screenshot from 2017-12-06 09:09:22
    3. API Token and Creadential
      5.Credential
      This is just a Sample App so I let you know the credential.

      Client ID: 281615142867.282451969317; Client Secret : a4071bfc70147832db46ba3844f85dff; Verification Token : Cv0JeOtgy0Dlh3T20zFWySHQ

    4. Your Slack App is ready to connect
  3. Comprehensive Introduction
  4. Sample Slackbot With Firebase
    1. Go to Google Cloud Console
    2. Create Google Cloud Project KrimiBotak (Of course we need a server)8.Create-GC-pROJECT9.Project-Created
    3. Setup App Engine
      10.SetupAppEngine
      Choose NodeJS and then pick a wanted server location

      12.project-created-follow-the-guide.png

    4. Follow the step-by-step GAE tutorial15.CONFIRM-PROJECT16.GOOGLE-CLOUD-SHELL17.clone-hello19.repo
      19.install-anrun
      install, set port and run the sample App

      20.web-preview

      22.Hello-word-is-running
      Hello Word on NodeJS Google App Engine

      22.deploy-appengine.png

      • If you got an error on deployment then you just need to run following command:
      • gcloud config set app/use_deprecated_preparation True21. Deploy-app.png

        25.running-app
        App Deployed on Google App Engine
    5. Go to Firebase console7.FIREBASE-CONSOLE13.CreateFirebaseProject14.add-project14.firebase-dashboar.png
    6. Firebase is ready now
    7. Test Firebase database / endpoint101.DatabaseFirebase103.set_node

      104.set-rules-to-public
      Set Public Enpoint
    8. Test endpoint access using POSTMAN105.postman1104.update
    9. Firebase database seems working properly
  5. Next setup NodeJS on my local machine

NodeJS Express Basic Tutorial

Setting up a Node (Express) development environment

Requirement

110.App-ENgine-Version
App Engine Shell
123.local-env
My Local Env

 

  1. Install NodeJS link
  2. Update NodeJS link
  3. Install NPM5 link

Create Project

  1. First create a directory for your new application and navigate into it:
    • mkdir krimibotak
      cd krimibotak
  2. Generate Project
    • npm init
  3. Install express js
    • npm install express --save
  4. package.json
    • 127.package.jsom
  5. *change index.js to app.js
  6. 125.app-run.png
    Masukkan keterangan
  7. Add Firebase
    • npm install --save firebase
      
  8. So far everything goes well, let’s learn to create RestAPI Using ExpressJS to warming up.
  9. Adjustment For Google App Engine

    1.modification-for-GAE
    new app.yml and modified app.js
    1.modification-for-GAE2
    app.js

    1.modification-for-GAE3
    app.yaml
  10. Deploy
    • gcloud app deploy –project krimibotak
  11. Create Simple Rest API

  12. Create api folder and some js files to start learning about basic functionality of ExpressJS Restful API development.
    • mkdir api && mkdir api/controllers api/models api/routes
    • touch api/controllers/testController.js api/models/testModel.js api/routes/testRoutes.js
    • 1.api-folder
      Sample API files (Not an Unit Test Files)
  13. Install nodemon
    • npm install –save-dev nodemon
    • npm install -g nodemon (we need it globally )

      103.nodemon-in-action
      Nodemon in action
  14. Install body-parser
    • npm install –save body-parser
  15. Current js files now are following:
    2.app-js
    app.js
    3.routes-js
    testRoutes.js
    4.controller
    testController.js

    201-basic-api201-basic-api2

  16. Setting up Firebase Database

    202-Firebase-DB-Connect-test
    Testing Firebase Realtime DB Connection
  17. Install firebase-tools for shell support
    npm install -g firebase-tools
  18. Menjalankan Server Web Lokal untuk Pengembangan
    firebase init
    110.firebase-ini
    105.database-connect
    firebase serve
    105.ups-Firebase-is-Error
    ups Firebase is Error
    199-noneed.png
    Remove all unwanted files

    107-movefirebase-to-controller
    Move all firebase from app.js to testController.js
  19. CRUD with Firebase Realtime Database
    129-header
    Required to post raw data
    161.empty-firebase
    Empty collection
    162.Firebase-first.png
    Create
    163.create-again
    Create again
    164.updated-cat
    Update a record
    165.read-cat.png
    Get a record

    166.deleted.png
    Delete
  20. Firebase is successfully tested.

Let’s start create the bot using this following documentation

link: https://get.slack.help/hc/en-us/articles/115005265703-Create-a-bot-for-your-workspace

Bot Name: krimibot

The Slack channel: https://kodinkanlah.slack.com/

  1. https://kodinkanlah.slack.com/apps/A0F7YS25R-bots
  2. 300
  3. 301
  4. 304

    306
    Please refer to our bot user API documentation, which tells you everything you need to know about setting up a bot integration.
  5. Our Gol is: Post messages and react to members307
  6. Node Library for the Slack APIs
    • $ npm install @slack/client –save
    • 309
  7. Slack Developer Kit for Node.js
    1. Try to send message to General  with WebApi320-send-to-chan-general305.png
  8. Start Bot309-bot-started.png
    401-the-krimi-bot
    Bot should be in a channel to work
    303-nochanel.png
    Native message
    304-mention-krimibot
    Mention the bot then “Invite them to join”
    303-invited
    Bot joined the general channel
    303-Greeting-from-Bot.png
    Greeting message from bot
    303-receive-message-from-channel
    Receives messages from Channel
    303-thanks-detection.png
    Thank / Karma detection
    304-max-karma-pont.png
    Everyone has 5 karma points to give out per day.

    304-sent-karma.png
    Firebase Realtime Database
  9. To be continue…

 

 

 

Urls:

  1. https://get.slack.help/hc/en-us/articles/115005265703-Create-a-bot-for-your-workspace
  2. Bot Info Page
  3. https://api.slack.com/bot-users
  4. https://slackapi.github.io/node-slack-sdk/bots#receiving-messages
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s