diff --git a/common_payload.go b/common_payload.go index 8b80d7a..f8b7992 100644 --- a/common_payload.go +++ b/common_payload.go @@ -71,3 +71,17 @@ type EmbeddedInfoPayload struct { // ID 各種ID(タイプによる) ID string `json:"id"` } + +// MessageStampPayload メッセージスタンプ情報 +type MessageStampPayload struct { + // StampID スタンプUUID + StampID string `json:"stampId"` + // UserID スタンプを押したユーザーUUID + UserID string `json:"userId"` + // Count このユーザーによって押されたこのスタンプの数 + Count int `json:"count"` + // CreatedAt 最初にスタンプが押された日時 + CreatedAt time.Time `json:"createdAt"` + // UpdatedAt 最後にスタンプが押された日時 + UpdatedAt time.Time `json:"updatedAt"` +} diff --git a/event_payload.go b/event_payload.go index d604d67..b45f484 100644 --- a/event_payload.go +++ b/event_payload.go @@ -26,6 +26,34 @@ type MessageCreatedPayload struct { Message MessagePayload `json:"message"` } +// MessageUpdatedPayload MESSAGE_UPDATEDイベントペイロード +type MessageUpdatedPayload struct { + BasePayload + // Message 更新されたメッセージ + Message MessagePayload `json:"message"` +} + +// MessageDeletedPayload MESSAGE_DELETEDイベントペイロード +type MessageDeletedPayload struct { + BasePayload + // Message 削除されたメッセージ + Message struct { + // ID メッセージUUID + ID string `json:"id"` + // ChannelID 投稿先チャンネルUUID + ChannelID string `json:"channelId"` + } `json:"message"` +} + +// BotMessageStampsUpdatedPayload BOT_MESSAGE_STAMPS_UPDATEDイベントペイロード +type BotMessageStampsUpdatedPayload struct { + BasePayload + // MessageID スタンプの更新があったメッセージUUID + MessageID string `json:"messageId"` + // Stamps メッセージに現在ついている全てのスタンプ + Stamps []MessageStampPayload `json:"stamps"` +} + // DirectMessageCreatedPayload DIRECT_MESSAGE_CREATEDイベントペイロード type DirectMessageCreatedPayload struct { BasePayload @@ -33,6 +61,27 @@ type DirectMessageCreatedPayload struct { Message MessagePayload `json:"message"` } +// DirectMessageUpdatedPayload DIRECT_MESSAGE_UPDATEDイベントペイロード +type DirectMessageUpdatedPayload struct { + BasePayload + // Message 更新されたメッセージ + Message MessagePayload `json:"message"` +} + +// DirectMessageDeletedPayload DIRECT_MESSAGE_DELETEDイベントペイロード +type DirectMessageDeletedPayload struct { + BasePayload + // Message 削除されたメッセージ + Message struct { + // ID メッセージUUID + ID string `json:"id"` + // UserID DMの宛先ユーザーUUID + UserID string `json:"userId"` + // ChannelID 投稿先チャンネルUUID + ChannelID string `json:"channelId"` + } `json:"message"` +} + // ChannelCreatedPayload CHANNEL_CREATEDイベントペイロード type ChannelCreatedPayload struct { BasePayload @@ -61,8 +110,30 @@ type UserCreatedPayload struct { // StampCreatedPayload STAMP_CREATEDイベントペイロード type StampCreatedPayload struct { BasePayload - ID string `json:"id"` - Name string `json:"name"` - FileID string `json:"fileId"` + // ID スタンプUUID + ID string `json:"id"` + // Name スタンプ名 + Name string `json:"name"` + // FileID スタンプ画像ファイルUUID + FileID string `json:"fileId"` + // Creator スタンプを作成したユーザー Creator UserPayload `json:"creator"` } + +// TagAddedPayload TAG_ADDEDイベントペイロード +type TagAddedPayload struct { + BasePayload + // TagID タグUUID + TagID string `json:"tagId"` + // Tag タグ名 + Tag string `json:"tag"` +} + +// TagRemovedPayload TAG_REMOVEDイベントペイロード +type TagRemovedPayload struct { + BasePayload + // TagID タグUUID + TagID string `json:"tagId"` + // Tag タグ名 + Tag string `json:"tag"` +} diff --git a/events.go b/events.go index 07b1f41..f4b8adb 100644 --- a/events.go +++ b/events.go @@ -1,22 +1,36 @@ package traqbot const ( - // Ping PINGイベント + // Ping Pingイベント Ping = "PING" - // Joined JOINEDイベント + // Joined チャンネル参加イベント Joined = "JOINED" - // Left LEFTイベント + // Left チャンネル退出イベント Left = "LEFT" - // MessageCreated MESSAGE_CREATEDイベント + // MessageCreated メッセージ作成イベント or メンションメッセージ作成イベント MessageCreated = "MESSAGE_CREATED" - // DirectMessageCreated DIRECT_MESSAGE_CREATEDイベント + // MessageUpdated メッセージ編集イベント + MessageUpdated = "MESSAGE_UPDATED" + // MessageDeleted メッセージ削除イベント + MessageDeleted = "MESSAGE_DELETED" + // BotMessageStampsUpdated BOTメッセージスタンプ更新イベント + BotMessageStampsUpdated = "BOT_MESSAGE_STAMPS_UPDATED" + // DirectMessageCreated ダイレクトメッセージ作成イベント DirectMessageCreated = "DIRECT_MESSAGE_CREATED" - // ChannelCreated CHANNEL_CREATEDイベント + // DirectMessageUpdated ダイレクトメッセージ編集イベント + DirectMessageUpdated = "DIRECT_MESSAGE_UPDATED" + // DirectMessageDeleted ダイレクトメッセージ削除イベント + DirectMessageDeleted = "DIRECT_MESSAGE_DELETED" + // ChannelCreated チャンネル作成イベント ChannelCreated = "CHANNEL_CREATED" - // ChannelTopicChanged CHANNEL_TOPIC_CHANGEDイベント + // ChannelTopicChanged チャンネルトピック変更イベント ChannelTopicChanged = "CHANNEL_TOPIC_CHANGED" - // UserCreated USER_CREATEDイベント + // UserCreated ユーザー作成イベント UserCreated = "USER_CREATED" - // StampCreated STAMP_CREATEDイベント + // StampCreated スタンプ作成イベント StampCreated = "STAMP_CREATED" + // TagAdded タグ追加イベント + TagAdded = "TAG_ADDED" + // TagRemoved タグ削除イベント + TagRemoved = "TAG_REMOVED" ) diff --git a/helper.go b/helper.go index 29fc628..7ea5949 100644 --- a/helper.go +++ b/helper.go @@ -31,11 +31,36 @@ func (hs EventHandlers) SetMessageCreatedHandler(h func(payload *MessageCreatedP hs.SetHandler(MessageCreated, func(event string, payload interface{}) { h(payload.(*MessageCreatedPayload)) }) } +// SetMessageUpdatedHandler イベントハンドラをセットします +func (hs EventHandlers) SetMessageUpdatedHandler(h func(payload *MessageUpdatedPayload)) { + hs.SetHandler(MessageUpdated, func(event string, payload interface{}) { h(payload.(*MessageUpdatedPayload)) }) +} + +// SetMessageDeletedHandler イベントハンドラをセットします +func (hs EventHandlers) SetMessageDeletedHandler(h func(payload *MessageDeletedPayload)) { + hs.SetHandler(MessageDeleted, func(event string, payload interface{}) { h(payload.(*MessageDeletedPayload)) }) +} + +// SetBotMessageStampsUpdatedHandler イベントハンドラをセットします +func (hs EventHandlers) SetBotMessageStampsUpdatedHandler(h func(payload *BotMessageStampsUpdatedPayload)) { + hs.SetHandler(BotMessageStampsUpdated, func(event string, payload interface{}) { h(payload.(*BotMessageStampsUpdatedPayload)) }) +} + // SetDirectMessageCreatedHandler イベントハンドラをセットします func (hs EventHandlers) SetDirectMessageCreatedHandler(h func(payload *DirectMessageCreatedPayload)) { hs.SetHandler(DirectMessageCreated, func(event string, payload interface{}) { h(payload.(*DirectMessageCreatedPayload)) }) } +// SetDirectMessageUpdatedHandler イベントハンドラをセットします +func (hs EventHandlers) SetDirectMessageUpdatedHandler(h func(payload *DirectMessageUpdatedPayload)) { + hs.SetHandler(DirectMessageUpdated, func(event string, payload interface{}) { h(payload.(*DirectMessageUpdatedPayload)) }) +} + +// SetDirectMessageDeletedHandler イベントハンドラをセットします +func (hs EventHandlers) SetDirectMessageDeletedHandler(h func(payload *DirectMessageDeletedPayload)) { + hs.SetHandler(DirectMessageDeleted, func(event string, payload interface{}) { h(payload.(*DirectMessageDeletedPayload)) }) +} + // SetChannelCreatedHandler イベントハンドラをセットします func (hs EventHandlers) SetChannelCreatedHandler(h func(payload *ChannelCreatedPayload)) { hs.SetHandler(ChannelCreated, func(event string, payload interface{}) { h(payload.(*ChannelCreatedPayload)) }) @@ -51,6 +76,17 @@ func (hs EventHandlers) SetUserCreatedHandler(h func(payload *UserCreatedPayload hs.SetHandler(UserCreated, func(event string, payload interface{}) { h(payload.(*UserCreatedPayload)) }) } +// SetStampCreatedHandler イベントハンドラをセットします func (hs EventHandlers) SetStampCreatedHandler(h func(payload *StampCreatedPayload)) { hs.SetHandler(StampCreated, func(event string, payload interface{}) { h(payload.(*StampCreatedPayload)) }) } + +// SetTagAddedHandler イベントハンドラをセットします +func (hs EventHandlers) SetTagAddedHandler(h func(payload *TagAddedPayload)) { + hs.SetHandler(TagAdded, func(event string, payload interface{}) { h(payload.(*TagAddedPayload)) }) +} + +// SetTagRemovedHandler イベントハンドラをセットします +func (hs EventHandlers) SetTagRemovedHandler(h func(payload *TagRemovedPayload)) { + hs.SetHandler(TagRemoved, func(event string, payload interface{}) { h(payload.(*TagRemovedPayload)) }) +} diff --git a/server.go b/server.go index bde3885..8f330d4 100644 --- a/server.go +++ b/server.go @@ -72,8 +72,18 @@ func (bs *BotServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { payload = &LeftPayload{} case MessageCreated: payload = &MessageCreatedPayload{} + case MessageUpdated: + payload = &MessageUpdatedPayload{} + case MessageDeleted: + payload = &MessageDeletedPayload{} + case BotMessageStampsUpdated: + payload = &BotMessageStampsUpdatedPayload{} case DirectMessageCreated: payload = &DirectMessageCreatedPayload{} + case DirectMessageUpdated: + payload = &DirectMessageUpdatedPayload{} + case DirectMessageDeleted: + payload = &DirectMessageDeletedPayload{} case ChannelCreated: payload = &ChannelCreatedPayload{} case ChannelTopicChanged: @@ -82,6 +92,10 @@ func (bs *BotServer) ServeHTTP(rw http.ResponseWriter, req *http.Request) { payload = &UserCreatedPayload{} case StampCreated: payload = &StampCreatedPayload{} + case TagAdded: + payload = &TagAddedPayload{} + case TagRemoved: + payload = &TagRemovedPayload{} default: rw.WriteHeader(http.StatusNotImplemented) return