本文整理匯總了Golang中github.com/nlopes/slack.NewPostMessageParameters函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewPostMessageParameters函數的具體用法?Golang NewPostMessageParameters怎麽用?Golang NewPostMessageParameters使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewPostMessageParameters函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
iniflags.Parse()
api := slack.New(*token)
//var channel_id string
channel_id := getChannelId(*channel, api)
var include, exclude *regexp.Regexp
var err error
if *includes != "" {
include, err = regexp.Compile(*includes)
if err != nil {
fmt.Println("ERROR: Failed to compile `line_includes` regex.")
fmt.Println(err)
api.PostMessage(channel_id, "==> slackd failed to compile `line_includes` regex.", slack.NewPostMessageParameters())
api.PostMessage(channel_id, err.Error(), slack.NewPostMessageParameters())
os.Exit(2)
}
}
if *excludes != "" {
exclude, err = regexp.Compile(*excludes)
if err != nil {
fmt.Println("ERROR: Failed to compile `line_excludes` regex.")
fmt.Println(err)
api.PostMessage(channel_id, "==> slackd failed to compile `line_excludes` regex.", slack.NewPostMessageParameters())
api.PostMessage(channel_id, err.Error(), slack.NewPostMessageParameters())
os.Exit(2)
}
}
log, err := tail.TailFile(*file, tail.Config{Follow: true, ReOpen: *reopen, Poll: true})
if err != nil {
fmt.Println("ERROR: Could not tail the specified log.")
fmt.Println(err)
api.PostMessage(channel_id, "==> slackd could not tail the specified log.", slack.NewPostMessageParameters())
api.PostMessage(channel_id, err.Error(), slack.NewPostMessageParameters())
os.Exit(2)
}
for line := range log.Lines {
if (include != nil && include.MatchString(line.Text)) || (exclude != nil && !exclude.MatchString(line.Text)) {
api.PostMessage(
channel_id,
fmt.Sprintf("```%s```", line.Text),
slack.NewPostMessageParameters())
}
}
}
示例2: postToSlack
func postToSlack(username string, channel string, message string, attachments string) {
param := slack.NewPostMessageParameters()
param.Username = username
dec := json.NewDecoder(strings.NewReader(attachments))
_ = dec.Decode(¶m.Attachments)
fmt.Printf("%v\n", param.Attachments)
_, _, err := ctx.slack.PostMessage(channel, message, param)
if err != nil {
log.WithFields(log.Fields{
"username": username,
"channel": channel,
"message": message,
"attachments": attachments,
}).Error(err.Error())
return
}
log.WithFields(log.Fields{
"username": username,
"channel": channel,
"message": message,
"attachments": attachments,
}).Info("posted")
}
示例3: performTask
func (rt ReconTask) performTask(task ActionItemConfig, stringContext map[string]interface{}) {
rt.log.Debug("Task Config - %v", task.Config)
switch task.Type {
case "sendToSlack":
message := EvaluateTemplate(task.Config["message"].(string), stringContext)
slackClient := slack.New(task.Config["slackKey"].(string))
slackClient.PostMessage(task.Config["slackTo"].(string), message, slack.NewPostMessageParameters())
case "executeMysql":
query := EvaluateTemplate(task.Config["query"].(string), stringContext)
params := task.Config["params"].([]interface{})
paramValues := make([]interface{}, 0)
for _, param := range params {
paramValue := EvaluateTemplate(param.(string), stringContext)
paramValues = append(paramValues, paramValue)
}
endPoint, err := NewMysqlDataProvider(task.Config["mysqlConfig"].(map[string]interface{}))
if err != nil {
rt.log.Error("Failed to connect to mysql - %v", err)
}
stmt, err := endPoint.db.Prepare(query)
if err != nil {
rt.log.Error("Failed to prepare statement- %v", err)
}
defer stmt.Close()
rt.log.Info("Executing [%s] with params [%v]", query, paramValues)
result, err := stmt.Exec(paramValues...)
if err != nil {
rt.log.Error("Failed to Execute query - %v", err)
}
count, _ := result.RowsAffected()
if count < 1 {
rt.log.Info("0 rows affected, might want to check - %v", stringContext)
}
}
}
示例4: Publish
// Publish Publishes messages to slack
func (x Slack) Publish(publishMsgs <-chan models.Message, connector models.Connector) {
api := slack.New(connector.Key)
for {
message := <-publishMsgs
msg := ""
params := slack.NewPostMessageParameters()
params.Username = connector.BotName
params.IconEmoji = connector.Image
if message.Out.Detail != "" {
color := slackColorMe(message.Out.Status)
attachment := slack.Attachment{
Title: message.Out.Text,
TitleLink: message.Out.Link,
Text: message.Out.Detail,
Color: color,
MarkdownIn: []string{"text"},
}
params.Attachments = []slack.Attachment{attachment}
} else {
msg = message.Out.Text
}
for _, target := range strings.Split(message.Out.Target, ",") {
if target == "*" {
target = message.In.Target
}
if target != "" && target != "*" {
api.PostMessage(target, msg, params)
}
}
}
}
示例5: Write
// expect some byte and write to slack
func (s *Slack) Write(o []byte) (n int, err error) {
outBuf := bytes.Buffer{}
outBuf.Write(o)
//s.rtm.SendMessage(
//s.rtm.NewOutgoingMessage(
//outBuf.String(),
//s.channel,
//),
//)
params := slack.NewPostMessageParameters()
params.Username = "supslack"
params.AsUser = true
params.Attachments = []slack.Attachment{
{
//AuthorName: authorName,
//AuthorIcon: authorIcon,
Text: fmt.Sprintf("%s\n\u2014\n", outBuf.String()), // \u200B for space
//ThumbURL: thumbURL,
//Fields: []AttachmentField{
//AttachmentField{
//Title: "",
//Value: fmt.Sprintf("*<%s|%s>*\n%s", post.ShortUrl, post.Title, description),
//Short: false,
//},
//},
MarkdownIn: []string{"text"},
}}
s.api.PostMessage(s.channel, "", params)
return len(o), nil
}
示例6: sendMessage
func sendMessage(sendWg *sync.WaitGroup, config *model.Config, api *slack.Client,
msg *model.ChatMessage) {
params := slack.NewPostMessageParameters()
params.Attachments = msg.Attachments
params.Username = config.SlackUser
params.IconURL = config.SlackIcon
params.LinkNames = 1
params.AsUser = false
channel := msg.Channel
if channel == "" {
// For now just print everything to the main channel. When we have RTM
// support up and running we might also want the ability to write back
// to a user DM channel.
channel = config.SlackDefaultChannel
}
logOut.Debugf("Posting to channel %s %s %+v", channel, msg.Text, params)
_, _, err := api.PostMessage(channel, msg.Text, params)
if err != nil {
logOut.Errorf("Error writing chat message: %s\n", err.Error())
}
sendWg.Done()
}
示例7: DefaultMessageParameters
// DefaultMessageParameters returns a default PostMessageParameters for vropsbot
func DefaultMessageParameters() (params slack.PostMessageParameters) {
params = slack.NewPostMessageParameters()
params.AsUser = true
params.EscapeText = false
return
}
示例8: Run
func (c *HelpCommand) Run(m *slack.MessageEvent, args ...string) {
params := slack.NewPostMessageParameters()
params.Attachments = []slack.Attachment{slack.Attachment{
Color: "good",
Fields: []slack.AttachmentField{},
}}
service := c.Service.(*SlackService)
if len(args) == 0 {
for name := range service.Commands {
params.Attachments[0].Fields = append(params.Attachments[0].Fields, slack.AttachmentField{
Title: service.Commands[name].GetName(),
Value: service.Commands[name].GetDescription(),
})
}
} else if command, ok := service.Commands[args[0]]; ok {
params.Attachments[0].Fields = append(params.Attachments[0].Fields, slack.AttachmentField{
Title: command.GetName(),
Value: command.GetDescription(),
})
} else {
c.SendMessagef(m.Channel, "Команда %s не найдена", args[0])
return
}
c.SendPostMessage(m.Channel, "Мои команды", params)
}
示例9: newPostMessageParams
func (s Slack) newPostMessageParams() slack.PostMessageParameters {
params := slack.NewPostMessageParameters()
if s.userName != "" {
params.Username = s.userName
}
if s.iconURL != "" {
params.IconURL = s.iconURL
}
return params
}
示例10: main
func main() {
if cli.file != "" {
log.Printf("Loading config from %s\n", cli.file)
f, err := os.Open(cli.file)
if err != nil {
log.Fatal(err)
}
defer f.Close()
err = json.NewDecoder(f).Decode(&settings)
if err != nil {
log.Fatal(err)
}
} else {
log.Fatal("You need to pass a json file to -config")
}
// override whats in the settings with whats on the cli
if cli.token != "" {
log.Printf("Slack token passed via CLI: %s\n", cli.token)
settings.Token = cli.token
}
if settings.Botname == "" || cli.botname != "" {
settings.Botname = cli.botname
}
if settings.Token == "" {
log.Fatal("You need to give me an API token!")
}
collins := c.New(settings.Collins.Username, settings.Collins.Password, settings.Collins.Host)
// set up posting params
postParams = slack.NewPostMessageParameters()
//postParams.Username = settings.Botname
//postParams.LinkNames = 1
// we will perform proper formatting per https://api.slack.com/docs/formatting, do make the server do no processing
postParams.Parse = "none"
api := slack.New(settings.Token)
api.SetDebug(cli.debug)
authresp, err := api.AuthTest()
if err != nil {
log.Fatal(err)
}
log.Printf("Authed with Slack successfully as %s (%s)\n", authresp.User, authresp.UserId)
log.Printf("Creating new handler context with message handlers:\n")
for _, v := range messagehandlers {
log.Printf(" %s\n", v)
}
handlerContext = handlers.New(collins, authresp, api, messagehandlers)
log.Printf("Starting up message handler")
handlerContext.Run()
}
示例11: statusToSlack
func statusToSlack(api *slack.Client, my_name string, channel string, msg string) {
params := slack.NewPostMessageParameters()
params.Username = my_name
params.IconEmoji = ":exclamation:"
attachment := slack.Attachment{}
attachment.Color = "#ffaa00"
attachment.Title = "Alarm Status Update"
attachment.Text = msg
params.Attachments = []slack.Attachment{attachment}
api.PostMessage(channel, "", params)
}
示例12: logToSlack
func logToSlack(api *slack.Client, my_name string, channel string, msg string, fields []slack.AttachmentField) {
params := slack.NewPostMessageParameters()
params.Username = my_name
params.IconEmoji = ":page_with_curl:"
attachment := slack.Attachment{}
attachment.Color = "#ffaa00"
attachment.Title = "Log Entry"
attachment.Text = msg
attachment.Fields = fields
params.Attachments = []slack.Attachment{attachment}
api.PostMessage(channel, "", params)
}
示例13: motionToSlack
func motionToSlack(api *slack.Client, my_name string, channel string, image string, count int) {
_, err := http.Get(image)
chk(err)
params := slack.NewPostMessageParameters()
params.Username = my_name
params.IconEmoji = ":rotating_light:"
attachment := slack.Attachment{}
attachment.Color = "#ff0000"
attachment.Title = "Motion detected"
attachment.Text = fmt.Sprintf("Motion events detected: %d", count)
attachment.ImageURL = image
params.Attachments = []slack.Attachment{attachment}
api.PostMessage(channel, "", params)
}
示例14: lightsToSlack
func lightsToSlack(api *slack.Client, my_name string, channel string, image string, level int) {
_, err := http.Get(image)
chk(err)
params := slack.NewPostMessageParameters()
params.Username = my_name
params.IconEmoji = ":bulb:"
attachment := slack.Attachment{}
attachment.Color = "#00ff00"
attachment.Title = "Lights detected"
attachment.Text = fmt.Sprintf("Light level detected: %d", level)
attachment.ImageURL = image
params.Attachments = []slack.Attachment{attachment}
api.PostMessage(channel, "", params)
}
示例15: Send
func (b *Bslack) Send(msg config.Message) error {
flog.Debugf("Receiving %#v", msg)
if msg.Account == b.Account {
return nil
}
nick := msg.Username
message := msg.Text
channel := msg.Channel
if b.Config.PrefixMessagesWithNick {
message = nick + " " + message
}
if !b.Config.UseAPI {
matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL}
matterMessage.Channel = channel
matterMessage.UserName = nick
matterMessage.Type = ""
matterMessage.Text = message
err := b.mh.Send(matterMessage)
if err != nil {
flog.Info(err)
return err
}
return nil
}
schannel, err := b.getChannelByName(channel)
if err != nil {
return err
}
np := slack.NewPostMessageParameters()
if b.Config.PrefixMessagesWithNick == true {
np.AsUser = true
}
np.Username = nick
np.IconURL = config.GetIconURL(&msg, b.Config)
if msg.Avatar != "" {
np.IconURL = msg.Avatar
}
b.sc.PostMessage(schannel.ID, message, np)
/*
newmsg := b.rtm.NewOutgoingMessage(message, schannel.ID)
b.rtm.SendMessage(newmsg)
*/
return nil
}