mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-19 01:22:38 +01:00
Use matterbridge vendored slack
This commit is contained in:
parent
b461fc5e40
commit
b2a6777995
0
vendor/github.com/nlopes/slack/dnd.go → vendor/github.com/matterbridge/slack/dnd.go
generated
vendored
0
vendor/github.com/nlopes/slack/dnd.go → vendor/github.com/matterbridge/slack/dnd.go
generated
vendored
0
vendor/github.com/nlopes/slack/im.go → vendor/github.com/matterbridge/slack/im.go
generated
vendored
0
vendor/github.com/nlopes/slack/im.go → vendor/github.com/matterbridge/slack/im.go
generated
vendored
0
vendor/github.com/nlopes/slack/rtm.go → vendor/github.com/matterbridge/slack/rtm.go
generated
vendored
0
vendor/github.com/nlopes/slack/rtm.go → vendor/github.com/matterbridge/slack/rtm.go
generated
vendored
38
vendor/github.com/nlopes/slack/users.go → vendor/github.com/matterbridge/slack/users.go
generated
vendored
38
vendor/github.com/nlopes/slack/users.go → vendor/github.com/matterbridge/slack/users.go
generated
vendored
@ -15,24 +15,26 @@ const (
|
|||||||
|
|
||||||
// UserProfile contains all the information details of a given user
|
// UserProfile contains all the information details of a given user
|
||||||
type UserProfile struct {
|
type UserProfile struct {
|
||||||
FirstName string `json:"first_name"`
|
FirstName string `json:"first_name"`
|
||||||
LastName string `json:"last_name"`
|
LastName string `json:"last_name"`
|
||||||
RealName string `json:"real_name"`
|
RealName string `json:"real_name"`
|
||||||
RealNameNormalized string `json:"real_name_normalized"`
|
RealNameNormalized string `json:"real_name_normalized"`
|
||||||
Email string `json:"email"`
|
DisplayName string `json:"display_name"`
|
||||||
Skype string `json:"skype"`
|
DisplayNameNormalized string `json:"display_name_normalized"`
|
||||||
Phone string `json:"phone"`
|
Email string `json:"email"`
|
||||||
Image24 string `json:"image_24"`
|
Skype string `json:"skype"`
|
||||||
Image32 string `json:"image_32"`
|
Phone string `json:"phone"`
|
||||||
Image48 string `json:"image_48"`
|
Image24 string `json:"image_24"`
|
||||||
Image72 string `json:"image_72"`
|
Image32 string `json:"image_32"`
|
||||||
Image192 string `json:"image_192"`
|
Image48 string `json:"image_48"`
|
||||||
ImageOriginal string `json:"image_original"`
|
Image72 string `json:"image_72"`
|
||||||
Title string `json:"title"`
|
Image192 string `json:"image_192"`
|
||||||
BotID string `json:"bot_id,omitempty"`
|
ImageOriginal string `json:"image_original"`
|
||||||
ApiAppID string `json:"api_app_id,omitempty"`
|
Title string `json:"title"`
|
||||||
StatusText string `json:"status_text,omitempty"`
|
BotID string `json:"bot_id,omitempty"`
|
||||||
StatusEmoji string `json:"status_emoji,omitempty"`
|
ApiAppID string `json:"api_app_id,omitempty"`
|
||||||
|
StatusText string `json:"status_text,omitempty"`
|
||||||
|
StatusEmoji string `json:"status_emoji,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// User contains all the information of a user
|
// User contains all the information of a user
|
21
vendor/github.com/nlopes/slack/examples/channels/channels.go
generated
vendored
21
vendor/github.com/nlopes/slack/examples/channels/channels.go
generated
vendored
@ -1,21 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
api := slack.New("YOUR_TOKEN_HERE")
|
|
||||||
channels, err := api.GetChannels(false)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, channel := range channels {
|
|
||||||
fmt.Println(channel.Name)
|
|
||||||
// channel is of type conversation & groupConversation
|
|
||||||
// see all available methods in `conversation.go`
|
|
||||||
}
|
|
||||||
}
|
|
30
vendor/github.com/nlopes/slack/examples/files/files.go
generated
vendored
30
vendor/github.com/nlopes/slack/examples/files/files.go
generated
vendored
@ -1,30 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
api := slack.New("YOUR_TOKEN_HERE")
|
|
||||||
params := slack.FileUploadParameters{
|
|
||||||
Title: "Batman Example",
|
|
||||||
//Filetype: "txt",
|
|
||||||
File: "example.txt",
|
|
||||||
//Content: "Nan Nan Nan Nan Nan Nan Nan Nan Batman",
|
|
||||||
}
|
|
||||||
file, err := api.UploadFile(params)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("Name: %s, URL: %s\n", file.Name, file.URL)
|
|
||||||
|
|
||||||
err = api.DeleteFile(file.ID)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("File %s deleted successfully.\n", file.Name)
|
|
||||||
}
|
|
22
vendor/github.com/nlopes/slack/examples/groups/groups.go
generated
vendored
22
vendor/github.com/nlopes/slack/examples/groups/groups.go
generated
vendored
@ -1,22 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
api := slack.New("YOUR_TOKEN_HERE")
|
|
||||||
// If you set debugging, it will log all requests to the console
|
|
||||||
// Useful when encountering issues
|
|
||||||
// api.SetDebug(true)
|
|
||||||
groups, err := api.GetGroups(false)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, group := range groups {
|
|
||||||
fmt.Printf("ID: %s, Name: %s\n", group.ID, group.Name)
|
|
||||||
}
|
|
||||||
}
|
|
32
vendor/github.com/nlopes/slack/examples/messages/messages.go
generated
vendored
32
vendor/github.com/nlopes/slack/examples/messages/messages.go
generated
vendored
@ -1,32 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
api := slack.New("YOUR_TOKEN_HERE")
|
|
||||||
params := slack.PostMessageParameters{}
|
|
||||||
attachment := slack.Attachment{
|
|
||||||
Pretext: "some pretext",
|
|
||||||
Text: "some text",
|
|
||||||
// Uncomment the following part to send a field too
|
|
||||||
/*
|
|
||||||
Fields: []slack.AttachmentField{
|
|
||||||
slack.AttachmentField{
|
|
||||||
Title: "a",
|
|
||||||
Value: "no",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
params.Attachments = []slack.Attachment{attachment}
|
|
||||||
channelID, timestamp, err := api.PostMessage("CHANNEL_ID", "Some text", params)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("Message successfully sent to channel %s at %s", channelID, timestamp)
|
|
||||||
}
|
|
123
vendor/github.com/nlopes/slack/examples/pins/pins.go
generated
vendored
123
vendor/github.com/nlopes/slack/examples/pins/pins.go
generated
vendored
@ -1,123 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
WARNING: This example is destructive in the sense that it create a channel called testpinning
|
|
||||||
*/
|
|
||||||
func main() {
|
|
||||||
var (
|
|
||||||
apiToken string
|
|
||||||
debug bool
|
|
||||||
)
|
|
||||||
|
|
||||||
flag.StringVar(&apiToken, "token", "YOUR_TOKEN_HERE", "Your Slack API Token")
|
|
||||||
flag.BoolVar(&debug, "debug", false, "Show JSON output")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
api := slack.New(apiToken)
|
|
||||||
if debug {
|
|
||||||
api.SetDebug(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
postAsUserName string
|
|
||||||
postAsUserID string
|
|
||||||
postToChannelID string
|
|
||||||
)
|
|
||||||
|
|
||||||
// Find the user to post as.
|
|
||||||
authTest, err := api.AuthTest()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error getting channels: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
channelName := "testpinning"
|
|
||||||
|
|
||||||
// Post as the authenticated user.
|
|
||||||
postAsUserName = authTest.User
|
|
||||||
postAsUserID = authTest.UserID
|
|
||||||
|
|
||||||
// Create a temporary channel
|
|
||||||
channel, err := api.CreateChannel(channelName)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
// If the channel exists, that means we just need to unarchive it
|
|
||||||
if err.Error() == "name_taken" {
|
|
||||||
err = nil
|
|
||||||
channels, err := api.GetChannels(false)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Could not retrieve channels")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, archivedChannel := range channels {
|
|
||||||
if archivedChannel.Name == channelName {
|
|
||||||
if archivedChannel.IsArchived {
|
|
||||||
err = api.UnarchiveChannel(archivedChannel.ID)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Could not unarchive %s: %s\n", archivedChannel.ID, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
channel = &archivedChannel
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error setting test channel for pinning: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
postToChannelID = channel.ID
|
|
||||||
|
|
||||||
fmt.Printf("Posting as %s (%s) in channel %s\n", postAsUserName, postAsUserID, postToChannelID)
|
|
||||||
|
|
||||||
// Post a message.
|
|
||||||
postParams := slack.PostMessageParameters{}
|
|
||||||
channelID, timestamp, err := api.PostMessage(postToChannelID, "Is this any good?", postParams)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error posting message: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grab a reference to the message.
|
|
||||||
msgRef := slack.NewRefToMessage(channelID, timestamp)
|
|
||||||
|
|
||||||
// Add message pin to channel
|
|
||||||
if err := api.AddPin(channelID, msgRef); err != nil {
|
|
||||||
fmt.Printf("Error adding pin: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// List all of the users pins.
|
|
||||||
listPins, _, err := api.ListPins(channelID)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error listing pins: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("\n")
|
|
||||||
fmt.Printf("All pins by %s...\n", authTest.User)
|
|
||||||
for _, item := range listPins {
|
|
||||||
fmt.Printf(" > Item type: %s\n", item.Type)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the pin.
|
|
||||||
err = api.RemovePin(channelID, msgRef)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error remove pin: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = api.ArchiveChannel(channelID); err != nil {
|
|
||||||
fmt.Printf("Error archiving channel: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
126
vendor/github.com/nlopes/slack/examples/reactions/reactions.go
generated
vendored
126
vendor/github.com/nlopes/slack/examples/reactions/reactions.go
generated
vendored
@ -1,126 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
var (
|
|
||||||
apiToken string
|
|
||||||
debug bool
|
|
||||||
)
|
|
||||||
|
|
||||||
flag.StringVar(&apiToken, "token", "YOUR_TOKEN_HERE", "Your Slack API Token")
|
|
||||||
flag.BoolVar(&debug, "debug", false, "Show JSON output")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
api := slack.New(apiToken)
|
|
||||||
if debug {
|
|
||||||
api.SetDebug(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
postAsUserName string
|
|
||||||
postAsUserID string
|
|
||||||
postToUserName string
|
|
||||||
postToUserID string
|
|
||||||
postToChannelID string
|
|
||||||
)
|
|
||||||
|
|
||||||
// Find the user to post as.
|
|
||||||
authTest, err := api.AuthTest()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error getting channels: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Post as the authenticated user.
|
|
||||||
postAsUserName = authTest.User
|
|
||||||
postAsUserID = authTest.UserID
|
|
||||||
|
|
||||||
// Posting to DM with self causes a conversation with slackbot.
|
|
||||||
postToUserName = authTest.User
|
|
||||||
postToUserID = authTest.UserID
|
|
||||||
|
|
||||||
// Find the channel.
|
|
||||||
_, _, chanID, err := api.OpenIMChannel(postToUserID)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error opening IM: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
postToChannelID = chanID
|
|
||||||
|
|
||||||
fmt.Printf("Posting as %s (%s) in DM with %s (%s), channel %s\n", postAsUserName, postAsUserID, postToUserName, postToUserID, postToChannelID)
|
|
||||||
|
|
||||||
// Post a message.
|
|
||||||
postParams := slack.PostMessageParameters{}
|
|
||||||
channelID, timestamp, err := api.PostMessage(postToChannelID, "Is this any good?", postParams)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error posting message: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grab a reference to the message.
|
|
||||||
msgRef := slack.NewRefToMessage(channelID, timestamp)
|
|
||||||
|
|
||||||
// React with :+1:
|
|
||||||
if err := api.AddReaction("+1", msgRef); err != nil {
|
|
||||||
fmt.Printf("Error adding reaction: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// React with :-1:
|
|
||||||
if err := api.AddReaction("cry", msgRef); err != nil {
|
|
||||||
fmt.Printf("Error adding reaction: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all reactions on the message.
|
|
||||||
msgReactions, err := api.GetReactions(msgRef, slack.NewGetReactionsParameters())
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error getting reactions: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("\n")
|
|
||||||
fmt.Printf("%d reactions to message...\n", len(msgReactions))
|
|
||||||
for _, r := range msgReactions {
|
|
||||||
fmt.Printf(" %d users say %s\n", r.Count, r.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// List all of the users reactions.
|
|
||||||
listReactions, _, err := api.ListReactions(slack.NewListReactionsParameters())
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error listing reactions: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("\n")
|
|
||||||
fmt.Printf("All reactions by %s...\n", authTest.User)
|
|
||||||
for _, item := range listReactions {
|
|
||||||
fmt.Printf("%d on a %s...\n", len(item.Reactions), item.Type)
|
|
||||||
for _, r := range item.Reactions {
|
|
||||||
fmt.Printf(" %s (along with %d others)\n", r.Name, r.Count-1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove the :cry: reaction.
|
|
||||||
err = api.RemoveReaction("cry", msgRef)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error remove reaction: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all reactions on the message.
|
|
||||||
msgReactions, err = api.GetReactions(msgRef, slack.NewGetReactionsParameters())
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error getting reactions: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("\n")
|
|
||||||
fmt.Printf("%d reactions to message after removing cry...\n", len(msgReactions))
|
|
||||||
for _, r := range msgReactions {
|
|
||||||
fmt.Printf(" %d users say %s\n", r.Count, r.Name)
|
|
||||||
}
|
|
||||||
}
|
|
46
vendor/github.com/nlopes/slack/examples/stars/stars.go
generated
vendored
46
vendor/github.com/nlopes/slack/examples/stars/stars.go
generated
vendored
@ -1,46 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
var (
|
|
||||||
apiToken string
|
|
||||||
debug bool
|
|
||||||
)
|
|
||||||
|
|
||||||
flag.StringVar(&apiToken, "token", "YOUR_TOKEN_HERE", "Your Slack API Token")
|
|
||||||
flag.BoolVar(&debug, "debug", false, "Show JSON output")
|
|
||||||
flag.Parse()
|
|
||||||
|
|
||||||
api := slack.New(apiToken)
|
|
||||||
if debug {
|
|
||||||
api.SetDebug(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get all stars for the usr.
|
|
||||||
params := slack.NewStarsParameters()
|
|
||||||
starredItems, _, err := api.GetStarred(params)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Error getting stars: %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for _, s := range starredItems {
|
|
||||||
var desc string
|
|
||||||
switch s.Type {
|
|
||||||
case slack.TYPE_MESSAGE:
|
|
||||||
desc = s.Message.Text
|
|
||||||
case slack.TYPE_FILE:
|
|
||||||
desc = s.File.Name
|
|
||||||
case slack.TYPE_FILE_COMMENT:
|
|
||||||
desc = s.File.Name + " - " + s.Comment.Comment
|
|
||||||
case slack.TYPE_CHANNEL, slack.TYPE_IM, slack.TYPE_GROUP:
|
|
||||||
desc = s.Channel
|
|
||||||
}
|
|
||||||
fmt.Printf("Starred %s: %s\n", s.Type, desc)
|
|
||||||
}
|
|
||||||
}
|
|
25
vendor/github.com/nlopes/slack/examples/team/team.go
generated
vendored
25
vendor/github.com/nlopes/slack/examples/team/team.go
generated
vendored
@ -1,25 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
api := slack.New("YOUR_TOKEN_HERE")
|
|
||||||
//Example for single user
|
|
||||||
billingActive, err := api.GetBillableInfo("U023BECGF")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("ID: U023BECGF, BillingActive: %v\n\n\n", billingActive["U023BECGF"])
|
|
||||||
|
|
||||||
//Example for team
|
|
||||||
billingActiveForTeam, err := api.GetBillableInfoForTeam()
|
|
||||||
for id, value := range billingActiveForTeam {
|
|
||||||
fmt.Printf("ID: %v, BillingActive: %v\n", id, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
17
vendor/github.com/nlopes/slack/examples/users/users.go
generated
vendored
17
vendor/github.com/nlopes/slack/examples/users/users.go
generated
vendored
@ -1,17 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
api := slack.New("YOUR_TOKEN_HERE")
|
|
||||||
user, err := api.GetUserInfo("U023BECGF")
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("%s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("ID: %s, Fullname: %s, Email: %s\n", user.ID, user.Profile.RealName, user.Profile.Email)
|
|
||||||
}
|
|
54
vendor/github.com/nlopes/slack/examples/websocket/websocket.go
generated
vendored
54
vendor/github.com/nlopes/slack/examples/websocket/websocket.go
generated
vendored
@ -1,54 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/nlopes/slack"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
api := slack.New("YOUR TOKEN HERE")
|
|
||||||
logger := log.New(os.Stdout, "slack-bot: ", log.Lshortfile|log.LstdFlags)
|
|
||||||
slack.SetLogger(logger)
|
|
||||||
api.SetDebug(true)
|
|
||||||
|
|
||||||
rtm := api.NewRTM()
|
|
||||||
go rtm.ManageConnection()
|
|
||||||
|
|
||||||
for msg := range rtm.IncomingEvents {
|
|
||||||
fmt.Print("Event Received: ")
|
|
||||||
switch ev := msg.Data.(type) {
|
|
||||||
case *slack.HelloEvent:
|
|
||||||
// Ignore hello
|
|
||||||
|
|
||||||
case *slack.ConnectedEvent:
|
|
||||||
fmt.Println("Infos:", ev.Info)
|
|
||||||
fmt.Println("Connection counter:", ev.ConnectionCount)
|
|
||||||
// Replace #general with your Channel ID
|
|
||||||
rtm.SendMessage(rtm.NewOutgoingMessage("Hello world", "#general"))
|
|
||||||
|
|
||||||
case *slack.MessageEvent:
|
|
||||||
fmt.Printf("Message: %v\n", ev)
|
|
||||||
|
|
||||||
case *slack.PresenceChangeEvent:
|
|
||||||
fmt.Printf("Presence Change: %v\n", ev)
|
|
||||||
|
|
||||||
case *slack.LatencyReport:
|
|
||||||
fmt.Printf("Current latency: %v\n", ev.Value)
|
|
||||||
|
|
||||||
case *slack.RTMError:
|
|
||||||
fmt.Printf("Error: %s\n", ev.Error())
|
|
||||||
|
|
||||||
case *slack.InvalidAuthEvent:
|
|
||||||
fmt.Printf("Invalid credentials")
|
|
||||||
return
|
|
||||||
|
|
||||||
default:
|
|
||||||
|
|
||||||
// Ignore other events..
|
|
||||||
// fmt.Printf("Unexpected: %v\n", msg.Data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
16
vendor/manifest
vendored
16
vendor/manifest
vendored
@ -286,6 +286,14 @@
|
|||||||
"branch": "master",
|
"branch": "master",
|
||||||
"notests": true
|
"notests": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"importpath": "github.com/matterbridge/slack",
|
||||||
|
"repository": "https://github.com/matterbridge/slack",
|
||||||
|
"vcs": "git",
|
||||||
|
"revision": "1c6e6305bf9c07fc603c9cf28f09ab0517a03120",
|
||||||
|
"branch": "matterbridge",
|
||||||
|
"notests": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"importpath": "github.com/mattermost/platform/einterfaces",
|
"importpath": "github.com/mattermost/platform/einterfaces",
|
||||||
"repository": "https://github.com/mattermost/platform",
|
"repository": "https://github.com/mattermost/platform",
|
||||||
@ -425,14 +433,6 @@
|
|||||||
"path": "/i18n",
|
"path": "/i18n",
|
||||||
"notests": true
|
"notests": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"importpath": "github.com/nlopes/slack",
|
|
||||||
"repository": "https://github.com/nlopes/slack",
|
|
||||||
"vcs": "git",
|
|
||||||
"revision": "5cde21b8b96a43fc3435a1f514123d14fd7eabdc",
|
|
||||||
"branch": "master",
|
|
||||||
"notests": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"importpath": "github.com/paulrosania/go-charset",
|
"importpath": "github.com/paulrosania/go-charset",
|
||||||
"repository": "https://github.com/paulrosania/go-charset",
|
"repository": "https://github.com/paulrosania/go-charset",
|
||||||
|
Loading…
Reference in New Issue
Block a user