Broid Slack Integration
Broid Integrations is an open source project providing a suite of Activity Streams 2 libraries for unified communications among a vast number of communication platforms.
Connect your App to Multiple Messaging Channels with One OpenSource Language.
Message types supported
Simple
Image
Video
Buttons
Location
Phone number
✅
✅
✅
✅
Location, Phone number are platform limitations.
Getting started
Register your app/bot on Slack
Instructions to create bot , can be found here .
Instructions to create app , can be found here .
Notes: Interactive message are only supported on app (with Oauth bot token).
You can generate one for test with this command: node bin/oauth.js --new -c client_id -s secret_id
Connect to Slack
import broidSlack from ' broid-slack '
const slack = new broidSlack ( {
token : ' xxxxx '
} )
slack . connect ( )
. subscribe ( {
next : data => console . log ( data ) ,
error : err => console . error ( ` Something went wrong: ${ err . message } ` ) ,
complete : ( ) => console . log ( ' complete ' ) ,
} )
Options availables
name
Type
default
Description
serviceID
string
random
Arbitrary identifier of the running instance
logLevel
string
info
Can be : fatal
, error
, warn
, info
, debug
, trace
token
string
Your access token
Receive a message
slack . listen ( )
. subscribe ( {
next : data => console . log ( ` Received message: ${ data } ` ) ,
error : err => console . error ( ` Something went wrong: ${ err . message } ` ) ,
complete : ( ) => console . log ( ' complete ' ) ,
} )
Post a message
To send a message, the format should use the broid-schemas .
const message_formated = ' ... '
slack . send ( message_formated )
. then ( ( ) => console . log ( " ok " ) )
. catch ( err => console . error ( err ) )
Buttons supported
This adapter support the interactive messages
Examples of messages
Message received
A direct message received from Sally
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" generator " : {
" id " : " 58a48f11-d623-475a-9335-80f9466ea08b " ,
" name " : " slack " ,
" type " : " Service "
} ,
" published " : 1483872057 ,
" type " : " Create " ,
" actor " : {
" id " : " U0K81Q8N3 " ,
" name " : " Sally " ,
" type " : " Person "
} ,
" target " : {
" id " : " D3LGCDRM1 " ,
" name " : " D3LGCDRM1 " ,
" type " : " Person "
} ,
" object " : {
" content " : " hello world " ,
" id " : " 1483872057.000018 " ,
" type " : " Note "
}
}
A message received from Sally on Channel/Group
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" generator " : {
" id " : " 58a48f11-d623-475a-9335-80f9466ea08b " ,
" name " : " slack " ,
" type " : " Service "
} ,
" published " : 1483872034 ,
" type " : " Create " ,
" actor " : {
" id " : " U0K81Q8N3 " ,
" name " : " Sally " ,
" type " : " Person "
} ,
" target " : {
" id " : " G3LT1PUN2 " ,
" name " : " G3LT1PUN2 " ,
" type " : " Group "
} ,
" object " : {
" content " : " hello world on group " ,
" id " : " 1483872034.000005 " ,
" type " : " Note "
}
}
A interactive message callback
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" published " : 1483495367 ,
" type " : " Create " ,
" generator " : {
" id " : " a99f63b0-aa77-40b4-8cf5-4ae3d694ed94 " ,
" type " : " Service " ,
" name " : " slack "
} ,
" object " : {
" type " : " Note " ,
" id " : " 1483495367.753793 " ,
" content " : " https://www.broid.ai " ,
" context " : {
" type " : " Object " ,
" name " : " interactive_message_callback " ,
" content " : " 03722c50-14d6-4501-a7d7-18c833079a49# https://hooks.slack.com/actions/xxxx/xxxxx "
}
} ,
" target " : {
" type " : " Group " ,
" id " : " C1L7YRBLG " ,
" name " : " channelname "
} ,
" actor " : {
" id " : " U0K81Q8N3 " ,
" type " : " Person " ,
" name " : " sally "
}
}
Send a message
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" type " : " Create " ,
" generator " : {
" id " : " f6e92eb6-f69e-4eae-8158-06613461cf3a " ,
" type " : " Service " ,
" name " : " slack "
} ,
" object " : {
" type " : " Note " ,
" content " : " hello world "
} ,
" to " : {
" type " : " Person " ,
" id " : " C1E3X0RRB "
}
}
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" type " : " Create " ,
" generator " : {
" id " : " f6e92eb6-f69e-4eae-8158-06613461cf3a " ,
" type " : " Service " ,
" name " : " slack "
} ,
" object " : {
" type " : " Note " ,
" content " : " hello world edited " ,
" id " : " 1483406119.000020 " ,
} ,
" to " : {
" type " : " Person " ,
" id " : " C1E3X0RRB "
}
}
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" type " : " Create " ,
" generator " : {
" id " : " f6e92eb6-f69e-4eae-8158-06613461cf3a " ,
" type " : " Service " ,
" name " : " slack "
} ,
" object " : {
" type " : " Note " ,
" content " : " " ,
" id " : " 1483406119.000020 " ,
} ,
" to " : {
" type " : " Person " ,
" id " : " C1E3X0RRB "
}
}
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" type " : " Create " ,
" generator " : {
" id " : " f6e92eb6-f69e-4eae-8158-06613461cf3a " ,
" type " : " Service " ,
" name " : " slack "
} ,
" object " : {
" type " : " Image " ,
" content " : " this is a image! " ,
" url " : " http://url_of/images/image.png "
} ,
" to " : {
" type " : " Group " ,
" id " : " C1L7YRBLG "
}
}
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" type " : " Create " ,
" generator " : {
" id " : " f6e92eb6-f69e-4eae-8158-06613461cf3a " ,
" type " : " Service " ,
" name " : " slack "
} ,
" object " : {
" type " : " Note " ,
" content " : " hello world " ,
" attachment " : [ {
" type " : " Button " ,
" content " : " Broid's website " ,
" name " : " broid " ,
" mediaType " : " text/html " ,
" url " : " https://www.broid.ai "
} , {
" type " : " Button " ,
" content " : " Falken's Maze Confirm " ,
" name " : " maze " ,
" url " : " value_maze " ,
" attachment " : {
" name " : " Falken's Maze " ,
" content " : " Can you confirm? " ,
" yesLabel " : " Yes " ,
" noLabel " : " No "
}
} ]
} ,
" to " : {
" type " : " Group " ,
" id " : " C1L7YRBLG "
}
}
Respond to interactive message
{
" @context " : " https://www.w3.org/ns/activitystreams " ,
" type " : " Create " ,
" generator " : {
" id " : " f6e92eb6-f69e-4eae-8158-06613461cf3a " ,
" type " : " Service " ,
" name " : " slack "
} ,
" object " : {
" type " : " Note " ,
" content " : " go for http://broid.ai " ,
" context " : {
" type " : " Object " ,
" name " : " interactive_message_callback " ,
" content " : " 03722c50-14d6-4501-a7d7-18c833079a49# https://hooks.slack.com/actions/xxxx/xxxxx "
} ,
} ,
" to " : {
" type " : " Group " ,
" id " : " C1L7YRBLG "
}
}
Contributing to Broid
Broid is an open source project. Broid wouldn't be where it is now without contributions by the community. Please consider forking Broid to improve, enhance or fix issues. If you feel like the community will benefit from your fork, please open a pull request.
And because we want to do the better for you. Help us improving Broid by
sharing your feedback on our Integrations GitHub Repo and let's build Broid together!
Code of Conduct
Make sure that you're read and understand the Code of Conduct .
Copyright & License
Copyright (c) 2016-2017 Broid.ai
This project is licensed under the AGPL 3, which can be
found here .