Skip to content

Instantly share code, notes, and snippets.

@Tanapruk
Last active July 18, 2018 10:13
Show Gist options
  • Save Tanapruk/684c7e608301d0643084b6ccdeb590e0 to your computer and use it in GitHub Desktop.
Save Tanapruk/684c7e608301d0643084b6ccdeb590e0 to your computer and use it in GitHub Desktop.
Slack API & stdlib

Project Structure of stdlib

functions
├── __main__.js
├── actions
│   ├── __main__.js
│   └── example.js
├── commands
│   ├── __main__.js
│   ├── hello.js
│   └── vacation.js
└── events
    ├── __main__.js
    └── message
        ├── __main__.js
        └── channel_join.js

functions is the folder that hold every function that interact with slack

__main__.js

  • This is to handle your HTML web page.

actions - intereaction with slack attachments

  • When you interact with a button or any element, it will callback to here.
  • slack admin: https://api.slack.com/apps/<uniqueAppId>/interactive-messages?
  • slack will POST at stdlib through here: https://<userid>.lib.id/<projectNameWithEnv>/actions
  • file name is action name, to call an action put the file name in the "name" field of action.

commands - when user type /<command>

  • Your slash command.
  • slack admin: https://api.slack.com/apps/<uniqueAppId>/slash-commands
  • slack will POST at stdlib through here: https://<userid>.lib.id/<projectNameWithEnv>/commands
  • file name is command. E.g., vacation.js is for /vacation.

events - subscribe to event API

  • E.g., When messages are sent to channel
  • slack admin: https://api.slack.com/apps/<uniqueAppId>/event-subscriptions
  • slack will POST at stdlib through here: https://<userid>.lib.id/<projectNameWithEnv>/events
  • file name/path is an event name.events/message/channel_join.js is for the event message.channel.join.. (NOT SURE)

Debug CLI

Here is how to test your codes using lib

parameter order (user, channel, text = '', event = {}, botToken = null, callback)

slash command

lib .commands.vacation trust -d

  • lib is the stdlib tool
  • .commands is to test slash command
  • .vacation is the command name
  • trust is the first parameter which is user name
  • -d is to show logs in command line

event

lib .events.message trust general "hey" -d

  • lib is the stdlib tool
  • .events is to test event command
  • .message is the event api name
  • trust is the first parameter which is user name
  • general is the second parameter which is channel
  • "hey" is the third parameter which is the message
  • -d is to show logs in command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment