Last active
June 21, 2020 04:08
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// v5.10.0で追加された、自分のみ閲覧可能なInteractive Messageを投稿する投稿するサンプル | |
// Go言語SDKのCreatePostEphemeralメソッドからは作成できなかったため、現在はプラグインの`SendEphemeralPost`からしか作成できない? | |
package main | |
import ( | |
"fmt" | |
"github.com/mattermost/mattermost-server/model" | |
"github.com/mattermost/mattermost-server/plugin" | |
) | |
type Plugin struct { | |
plugin.MattermostPlugin | |
} | |
func main() { | |
plugin.ClientMain(&Plugin{}) | |
} | |
func (p *Plugin) OnActivate() error { | |
return p.API.RegisterCommand(&model.Command{ | |
Trigger: "mm510-eim", | |
AutoComplete: true, | |
}) | |
} | |
func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) { | |
post := &model.Post{ | |
Type: model.POST_EPHEMERAL, | |
ChannelId: args.ChannelId, | |
Props: model.StringInterface{ | |
"attachments": []*model.SlackAttachment{ | |
{ | |
Text: "test", | |
Actions: []*model.PostAction{ | |
{ | |
Type: model.POST_ACTION_TYPE_SELECT, | |
Name: "TEST", | |
DataSource: "channels", | |
Integration: &model.PostActionIntegration{ | |
URL: fmt.Sprintf("%s/eim", ""), | |
}, | |
}, | |
}, | |
}, | |
}, | |
}, | |
} | |
post.Message = "SendEphemeralPost" | |
p.API.SendEphemeralPost(args.UserId, post) | |
return &model.CommandResponse{ | |
Text: "test", | |
}, nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io" | |
"log" | |
"net/http" | |
"github.com/mattermost/mattermost-server/model" | |
) | |
const ( | |
ServerURL = "http://localhost:8080" | |
MattermostURL = "http://localhost:8065" | |
AccessToken = "yj4xzckhiig5urrdzm4ydduccc" | |
) | |
var client *model.Client4 | |
func main() { | |
client = model.NewAPIv4Client(MattermostURL) | |
client.SetOAuthToken(AccessToken) | |
http.HandleFunc("/multi", handleMultiResponse) | |
if err := http.ListenAndServe(":8080", nil); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func handleMultiResponse(w http.ResponseWriter, r *http.Request) { | |
resp := model.CommandResponse{ | |
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, | |
Text: "Multi Response Sample", | |
ExtraResponses: []*model.CommandResponse{ | |
{ | |
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, | |
Text: "Sample Response1", | |
}, | |
{ | |
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, | |
Text: "Sample Response2(Ephemeral)", | |
}, | |
}, | |
} | |
w.Header().Add("Content-Type", "application/json") | |
io.WriteString(w, resp.ToJson()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// v5.8.0より有効になった、スラッシュコマンド実行時のレスポンスメッセージを別のチャンネルに投稿するサンプル | |
// L31で別のチャンネルのIDを指定しています。 | |
package main | |
import ( | |
"io" | |
"log" | |
"net/http" | |
"github.com/mattermost/mattermost-server/model" | |
) | |
const ( | |
ServerURL = "http://localhost:8080" | |
MattermostURL = "http://localhost:8066" | |
OtherChannelID = "csg7u95tipn63ciybec6whb8ao" | |
) | |
func main() { | |
http.HandleFunc("/multi", handleMultiResponse) | |
if err := http.ListenAndServe(":8080", nil); err != nil { | |
log.Fatal(err) | |
} | |
} | |
func handleMultiResponse(w http.ResponseWriter, r *http.Request) { | |
resp := model.CommandResponse{ | |
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, | |
Text: "Multi Response Sample", | |
ExtraResponses: []*model.CommandResponse{ | |
{ | |
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, | |
ChannelId: OtherChannelID, | |
Text: "Sample Response1 to other channel", | |
}, | |
{ | |
ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL, | |
Text: "Sample Response2(Ephemeral)", | |
}, | |
}, | |
} | |
w.Header().Add("Content-Type", "application/json") | |
io.WriteString(w, resp.ToJson()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment