Coder Social home page Coder Social logo

mfix22 / botkit-helper-slack Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 1.0 11 KB

:loudspeaker: Functions for helping your Slack bot get its point across.

License: MIT License

JavaScript 100.00%
botkit-helper-slack botkit slack helper util bots bot

botkit-helper-slack's Introduction

botkit-helper-slack

Helps Slack bots get their point across

Never have to look up how to use bold, italics, strikethrough, code, pre... formats again for Slack API (I still had to look it all up for this Github Markdown though).

Getting started

$ npm install --save botkit-helper-slack

Usage

var SS = require('botkit-helper-slack');

SS('My Emphatic Decree!').italic()  // -> '_My Emphatic Decree!_' (in Slack italics)

// or
SS.extendPrototype()
'var meta = x'.slackCode() // -> '`var meta = x`' (in Slack code format)

Methods

Calling extendPrototype() will extend the Javascript String prototype, but in order to not poison the String namespace, each function name will start with 'slack' and maintain camelCase format

e.g. italic -> slackItalic

SS('I really need to italicize this').italic() //-> "_I really need to italicize this_"

// or extend the String prototype
SS.extendPrototype()
'and this one'.slackItalic() //-> "_and this one_"
.italic( ) (slackItalic)

Italicizes your string according to Slack format 'italics' -> '_italics_' italics

.bold( ) (slackBold)

Bolds your string according to Slack format 'bold' -> '*bold*' bold

.code( ) (slackCode)

Makes your string look like code according to Slack format 'code' -> '`code`' code

.pre( ) (slackPre)

Makes your string look like pre-formatted fixed width text according to Slack format 'pre' -> '```pre```'

pre
.strike( ) (slackStrike)

Strikes through your string, according to Slack format 'strike' -> '~strike~' strike

.quote( ) (slackQuote)

Creates a single line quote. This function does not surround your string with quotes. 'quote' -> '> quote'

quote

.paragraph( ) (slackParagraph)

Creates a multi-line quote. 'paragraph' -> '>>> paragraph'

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris

.emoji( ) (slackEmoji)

Formats your string into Slack emoji style.

('Do NOT Litter').emoji( ) //-> ':do_not_litter:'`

๐Ÿšฏ

.user( ) (slackUser)

Formats your user ID into Slack's desired format 'U112233' -> '<@U112233>'

.channel( ) (slackChannel)

Formats your channel ID into Slack's desired format 'C445566' -> '<@C445566>'

.subteam(handle) (slackSubteam)

Will create message linking to the subteam ID viewed as required @handle

// having called extendPrototype()
'S289524'.slackSubteam('the-homies') //-> '<!subteam^S289524|the-homies>'
.date(options) (slackDate)

Formats your date using optional options. Date can be a seconds since the epoch, a string, or an instance of Date

SS(1526249506).date() // -> '<!date^1526249506^{date}|Sun, 13 May 2018 22:11:46 GMT>'
SS(new Date()).date()
SS('2018-05-13').date()

var options = {format: '{date} at {time}', link: 'http://example.com', fallback: 'Some great date'};
SS('1526249506').date(options) // -> '<!date^1526249506^{date} at {time}^http://example.com|Some great date>');

// having called extendPrototype()
'2018-05-13'.slackDate(options)
.url(handle) (slackSubteam)

Creates a formatted link displayed as optional handle

// having called extendPrototype()
'https://mfix22.github.io'.slackUrl('My Portfolio') //-> '<https://mfix22.github.io/|My Portfolio>'

My Portfolio

.email(handle) (slackEmail)

Creates a formatted mailto: email link displayed at handle

// having called extendPrototype()
'[email protected]'.slackEmail('Email Me') //-> '<mailto:[email protected]|Email Me>'

Email Me

.atHere( ) (slackAtHere)

See get('here')

.atEveryone( ) (slackAtEveryone)

See get('everyone')

.atGroup( ) (slackAtGroup)

See get('group')

.atChannel( ) (slackAtChannel)

See get('channel')

.html( ) (slackHtml)

Formats your HTML code using Slack desired format.

SS('<div></div>').html() //-> '&lt;div&gt;&lt;/div&gt;

Helpers

Other functions to help you format Slack messages

.get(key)

Will return the corresponding string value for each key below.

key value (string)
'bullet' โ€ข
'here' <!here|here>
'channel' <!channel>
'group' <!group>
'everyone' <!everyone>

Test

$ npm test

botkit-helper-slack's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

botkit-helper-slack's Issues

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.