Create slash commands to allow each MM user to connect to their twitter account.#9
Create slash commands to allow each MM user to connect to their twitter account.#9chetanyakan wants to merge 8 commits intomattermost-community:masterfrom
Conversation
|
@chetanyakan @larkox This seems like a perfect application for https://github.com/mattermost/mattermost-plugin-api/tree/master/experimental/oauther. Thoughts? |
aaronrothschild
left a comment
There was a problem hiding this comment.
Thanks for your contribution @chetanyakan ! I'll defer to @larkox and @levb on technical implementation but UI so far looks good!
|
@levb The implementation in experminetal/oather seems to be for OAuth 2. Twitter uses Refer: https://developer.twitter.com/en/docs/authentication/overview My implementation here is for |
|
Thx for clarifying, I commented before I read the code in detail. Let me review now. |
larkox
left a comment
There was a problem hiding this comment.
Awesome work! There are a few small comments, but apart of that, it looks fantastic. I may even take some ideas for other plugins 😄 Thanks!
| if err != nil { | ||
| c.api.LogError("twitterLoginCallback: Failed to verify twitter credentials for connected user.", "Error", err.Error()) | ||
| http.Error(w, err.Error(), http.StatusInternalServerError) | ||
| return | ||
| } | ||
| if resp != nil { | ||
| defer resp.Body.Close() | ||
| } |
There was a problem hiding this comment.
Should we check the StatusCode of the response, or that is handled somewhere else?
| ChannelId: channelID, | ||
| Message: message, | ||
| } | ||
| post.SetProps(model.StringInterface{ |
There was a problem hiding this comment.
As far as I know, this is not needed. You can just put the UserID in the post as the bot id, and it will work the same way, right? Or is there any reason to do it this way?
| "default": "LwAgBVckO0EQlI2zka55ZFAN16xMRY8T0zvzVI4KbVlCK6tBN1" | ||
| }, | ||
| { | ||
| "key": "EncryptionKey", |
There was a problem hiding this comment.
Are we using this? In theory, there is no need to encrypt the tokens, so you can get rid of this and the logic around the encryption.
There was a problem hiding this comment.
I agree with @larkox. There doesn't seem to be a need to encrypt them.
hanzei
left a comment
There was a problem hiding this comment.
Thanks for the great work 👍
Looking forward on what can be done with this plugin.
| # Jetbrains | ||
| .idea/ | ||
|
|
||
| vendor |
There was a problem hiding this comment.
When using this repo outside $GOPATH, we need to vendor the dependencies using go mod vendor for IDE auto-complete.
Should I add this to my local .gitignore file?
| require ( | ||
| github.com/dghubble/go-twitter v0.0.0-20201011215211-4b180d0cc78d | ||
| github.com/dghubble/oauth1 v0.6.0 | ||
| github.com/google/go-cmp v0.5.1 // indirect |
There was a problem hiding this comment.
Nit pick: Please remove the indirect dependencies.
| "description": "A Matermost plugin to connect to Twitter.", | ||
| "version": "0.1.0", | ||
| "min_server_version": "5.12.0", | ||
| "min_server_version": "5.27.0", |
There was a problem hiding this comment.
What 5.27.0 feature does this plugin use?
| func GetCommand(iconData string) *model.Command { | ||
| return &model.Command{ | ||
| Trigger: "twitter", | ||
| DisplayName: "Twitter", |
There was a problem hiding this comment.
Plugin don't need a DisplayName. Mind removing this?
|
|
||
| func twitterConnect(ctx *Context, args ...string) (*model.CommandResponse, *model.AppError) { | ||
| // If the user is already connected to twitter. | ||
| if twUser, err := ctx.store.GetTwitterUser(ctx.UserId); err == nil && twUser != nil { |
There was a problem hiding this comment.
Added a log in the store method before return.
| return nil | ||
| } | ||
|
|
||
| func (s Store) StoreTTL(key string, data []byte, ttlSeconds int64) error { |
There was a problem hiding this comment.
Does this need to get exported?
| return nil | ||
| } | ||
|
|
||
| func (s Store) StoreWithOptions(key string, value []byte, opts model.PluginKVSetOptions) (bool, error) { |
There was a problem hiding this comment.
Does this need to get exported?
| return success, nil | ||
| } | ||
|
|
||
| func (s Store) Delete(key string) error { |
There was a problem hiding this comment.
Does this need to get exported?
| if len(data) == 0 { | ||
| return ErrNotFound | ||
|
|
||
| // TODO: Remove this |
There was a problem hiding this comment.
Should that todo get resolved?
|
|
||
| // Ensure makes sure the initial value for a key is set to the value provided, if it does not already exists | ||
| // Returns the value set for the key in kv-store and error | ||
| func (s *Store) Ensure(key string, newValue []byte) ([]byte, error) { |
|
/update-branch |
|
@chetanyakan Sorry for tinkering with your branch. CI is working now: https://app.circleci.com/pipelines/github/mattermost/mattermost-plugin-twitter/2/workflows/1b7a6e98-36df-414d-98e2-19f50e4345b1/jobs/6 |
|
Thanks, @hanzei! I'll pull these changes. |
hanzei
left a comment
There was a problem hiding this comment.
Thanks for updating the PR! A few things still seem unresolved .
| # Jetbrains | ||
| .idea/ | ||
|
|
||
| vendor |
| return data, nil | ||
| } | ||
|
|
||
| func (s Store) Store(key string, data []byte) error { |
There was a problem hiding this comment.
This also seems unresolved.



Summary
Ticket Link
#6