-
Notifications
You must be signed in to change notification settings - Fork 14
Added Feature to handle reaction add & get message text of a reaction #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bff4a1e
de00726
742d1ea
66ddeab
3aed651
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,10 @@ Pack requires go version min. 1.11 | |
|
|
||
| The plugin is configured using environment variables: | ||
|
|
||
| ENV VAR | Default | Description | Example | ||
| ------------------------------- | ------- | ----------------------------------------- | --------------------- | ||
| FLYTE_API | - | The API endpoint to use | http://localhost:8080 | ||
| FLYTE_SLACK_TOKEN | - | The Slack Bot API token to use | token_abc | ||
| | ENV VAR | Default | Description | Example | | ||
| |-------------------|---------|--------------------------------|-----------------------| | ||
| | FLYTE_API | - | The API endpoint to use | http://localhost:8080 | | ||
| | FLYTE_SLACK_TOKEN | - | The Slack Bot API token to use | token_abc | | ||
|
|
||
| Example `FLYTE_API=http://localhost:8080 FLYTE_SLACK_TOKEN=token_abc ./flyte-slack` | ||
|
|
||
|
|
@@ -71,11 +71,28 @@ The returned event payload is the same as the input. | |
| `SendRichMessageFailed` | ||
| ```json | ||
| { | ||
| "inputMessage": { ... }, | ||
| "inputMessage": { | ||
| }, | ||
| "error": "..." | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
| ### GetReactionMessageInfo | ||
| This command would retrieve the message text of reaction sent by a user. | ||
|
|
||
| ``` | ||
| { "count": 50 , //default value is 100 mandatory | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure yet what this is doing. What
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The count of reactions in list sorted via timestamp. Hope this clarifies. |
||
| "message": "" , | ||
| "threadTimestamp":"...", | ||
| "reactionUser":"...", // mandatory list of reactions for a user | ||
| "channelId": "...", | ||
| "threadTimestamp":"..." | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this is typo I would rectify this. |
||
| } | ||
| ``` | ||
|
Comment on lines
+84
to
+92
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tabs/spaces seem to be off on this one. can you align to left with just one tab pelase? |
||
|
|
||
|
|
||
|
|
||
| ## Events | ||
|
|
||
| ### ReceivedMessage | ||
|
|
@@ -95,6 +112,24 @@ The returned event payload is the same as the input. | |
| "message": "..." | ||
| } | ||
|
|
||
| ### ReactionAdded | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be wrong according to There is no such thing as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is some reason, which go slack module version are you referring to? I am referring to slack@v0.9.1>websocket_reactions.go contains below definition. Can you please cross check again?
type reactionEvent struct { // ReactionAddedEvent represents the Reaction added event // ReactionRemovedEvent represents the Reaction removed event |
||
| "type":"reaction_added", | ||
| "user":"...", //user that adds the reaction | ||
| "itemUser":"...", //user that writes the message, file etc. | ||
| "item": { | ||
| "type" :"message", | ||
| "channel" :"...", | ||
| "file" :"", | ||
| "fileComment" :"", | ||
| "timestamp" :"..." | ||
| }, | ||
| "reaction" :"...", //value of the reaction | ||
| "eventTimestamp" :"..." | ||
| } | ||
|
|
||
|
|
||
|
|
||
| ## Example Flows | ||
|
|
||
| The following flow will allow you to type any message into a Slack channel where this pack is | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -321,3 +321,8 @@ func (m *MockClient) PostMessage(channel string, opts ...slack.MsgOption) (strin | |
| func (m *MockClient) GetConversations(params *slack.GetConversationsParameters) (channels []slack.Channel, nextCursor string, err error) { | ||
| return nil, "", err | ||
| } | ||
| func (m *MockClient) ListReactions(params slack.ListReactionsParameters) ([]slack.ReactedItem, *slack.Paging, error) { | ||
| params = params | ||
| //TODO mock the list reactions | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is still hasn't been dealt with |
||
| return nil, nil, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| Copyright (C) 2018 Expedia Group. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package command | ||
|
|
||
| import ( | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| "testing" | ||
| ) | ||
|
|
||
| var ReactionMockSlack *MockSlack | ||
|
|
||
| func TestGetReactionListCommandIsPopulated(t *testing.T) { | ||
|
|
||
| command := GetReactionMessageInfo(ReactionMockSlack) | ||
|
|
||
| assert.Equal(t, "GetReactionMessageInfo", command.Name) | ||
| require.Equal(t, 2, len(command.OutputEvents)) | ||
| assert.Equal(t, "GetReactionMessageInfoSuccess", command.OutputEvents[0].Name) | ||
| assert.Equal(t, "GetReactionMessageInfoFailed", command.OutputEvents[1].Name) | ||
| } | ||
|
|
||
| func TestGetReactionListReturnsGetReactionListSuccess(t *testing.T) { | ||
|
|
||
| BeforeMessage() | ||
| defer AfterMessage() | ||
|
|
||
| handler := GetReactionMessageInfo(ReactionMockSlack).Handler | ||
| event := handler([]byte(`{"count": 50 , | ||
| "message": "" , | ||
| "threadTimestamp":"1645441176.871569", | ||
| "reactionUser":"UXXXXXX", | ||
| "channelId": "CXXXXXXX", | ||
| "threadTimestamp":"1645441176.871569" | ||
| }`)) | ||
| output := event.Payload.(GetReactionMessageInfoOutput) | ||
| assert.Equal(t, "GetReactionMessageInfoSuccess", event.EventDef.Name) | ||
| assert.Equal(t, "", output.Message) | ||
| assert.Equal(t, "CXXXXXXX", output.ChannelId) | ||
| } | ||
|
|
||
| func TestGetReactionListReturnsGetReactionMessageInfoFailedMissingTimestamp(t *testing.T) { | ||
|
|
||
| BeforeMessage() | ||
| defer AfterMessage() | ||
|
|
||
| handler := GetReactionMessageInfo(ReactionMockSlack).Handler | ||
| event := handler([]byte(`{"count": 50 , | ||
| "message": "" , | ||
| "reactionUser":"UXXXXXX", | ||
| "channelId": "CXXXXXXX", | ||
| "threadTimestamp":"" | ||
| }`)) | ||
| output := event.Payload.(GetReactionMessageInfoFailed) | ||
| output = output | ||
| assert.Equal(t, "GetReactionMessageInfoFailed", event.EventDef.Name) | ||
| assert.Equal(t, "missing Message Timestamp field", output.Error) | ||
| } | ||
|
|
||
| func TestGetReactionListReturnsGetReactionMessageInfoFailedMissingReactionUser(t *testing.T) { | ||
|
|
||
| BeforeMessage() | ||
| defer AfterMessage() | ||
|
|
||
| handler := GetReactionMessageInfo(ReactionMockSlack).Handler | ||
| event := handler([]byte(`{"count": 50 , | ||
| "message": "" , | ||
| "reactionUser":"", | ||
| "channelId": "CXXXXXXX", | ||
| "threadTimestamp":"213.4445" | ||
| }`)) | ||
| output := event.Payload.(GetReactionMessageInfoFailed) | ||
| output = output | ||
| assert.Equal(t, "GetReactionMessageInfoFailed", event.EventDef.Name) | ||
| assert.Equal(t, "missing user id field", output.Error) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package command | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "fmt" | ||
| "github.com/ExpediaGroup/flyte-slack/client" | ||
| "github.com/HotelsDotCom/flyte-client/flyte" | ||
| "strings" | ||
| ) | ||
|
|
||
| var ( | ||
| getReactionMessageInfoEventDef = flyte.EventDef{Name: "GetReactionMessageInfoSuccess"} | ||
| getReactionMessageInfoFailedEventDef = flyte.EventDef{Name: "GetReactionMessageInfoFailed"} | ||
| ) | ||
|
|
||
| type GetReactionMessageInfoInput struct { | ||
| Count int `json:"count"` | ||
| Message string `json:"message"` | ||
| ThreadTimestamp string `json:"threadTimestamp"` | ||
| User string `json:"reactionUser"` | ||
| ChannelId string `json:"channelId"` | ||
| ItemUser string `json:"itemUser"` | ||
| } | ||
|
|
||
| type GetReactionMessageInfoOutput struct { | ||
| GetReactionMessageInfoInput | ||
| } | ||
|
|
||
| type GetReactionMessageInfoFailed struct { | ||
| GetReactionMessageInfoOutput | ||
| Error string `json:"error"` | ||
| } | ||
|
|
||
| func GetReactionMessageInfo(slack client.Slack) flyte.Command { | ||
|
|
||
| return flyte.Command{ | ||
| Name: "GetReactionMessageInfo", | ||
| OutputEvents: []flyte.EventDef{getReactionMessageInfoEventDef, getReactionMessageInfoFailedEventDef}, | ||
| Handler: getReactionMessageInfoHandler(slack), | ||
| } | ||
| } | ||
|
|
||
| func getReactionMessageInfoHandler(slack client.Slack) func(json.RawMessage) flyte.Event { | ||
|
|
||
| return func(rawInput json.RawMessage) flyte.Event { | ||
| input := GetReactionMessageInfoInput{} | ||
| if err := json.Unmarshal(rawInput, &input); err != nil { | ||
| return flyte.NewFatalEvent(fmt.Sprintf("input is not valid: %v", err)) | ||
| } | ||
|
|
||
| errorMessages := []string{} | ||
| if input.ThreadTimestamp == "" { | ||
| errorMessages = append(errorMessages, "missing Message Timestamp field") | ||
| } | ||
| if input.ChannelId == "" { | ||
| errorMessages = append(errorMessages, "missing channel id field") | ||
| } | ||
| if input.User == "" { | ||
| errorMessages = append(errorMessages, "missing user id field") | ||
| } | ||
| if len(errorMessages) != 0 { | ||
| return getReactionMessageFailedEvent(input.Message, input.ChannelId, strings.Join(errorMessages, ", ")) | ||
| } | ||
|
|
||
| issueSummary := slack.GetReactionMessageText(input.Count, input.User, input.ChannelId, input.ThreadTimestamp) | ||
| return getReactionMessageSuccessInfoEvent(issueSummary, input.ChannelId) | ||
| } | ||
| } | ||
|
|
||
| func getReactionMessageSuccessInfoEvent(message, channelId string) flyte.Event { | ||
|
|
||
| return flyte.Event{ | ||
| EventDef: getReactionMessageInfoEventDef, | ||
| Payload: GetReactionMessageInfoOutput{GetReactionMessageInfoInput: GetReactionMessageInfoInput{Message: message, ChannelId: channelId}}, | ||
| } | ||
| } | ||
|
|
||
| func getReactionMessageFailedEvent(message, channelId string, err string) flyte.Event { | ||
|
|
||
| output := GetReactionMessageInfoOutput{GetReactionMessageInfoInput{Message: message, ChannelId: channelId}} | ||
| return flyte.Event{ | ||
| EventDef: getReactionMessageInfoFailedEventDef, | ||
| Payload: GetReactionMessageInfoFailed{GetReactionMessageInfoOutput: output, Error: err}, | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to understand use case for this one and what it actually does 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem with the previous implementation: JSON standard does not allow such tokens.
To fix this, I have removed the ... token.