Skip to content

Create slash commands to allow each MM user to connect to their twitter account.#9

Open
chetanyakan wants to merge 8 commits intomattermost-community:masterfrom
chetanyakan:GH-6
Open

Create slash commands to allow each MM user to connect to their twitter account.#9
chetanyakan wants to merge 8 commits intomattermost-community:masterfrom
chetanyakan:GH-6

Conversation

@chetanyakan
Copy link
Copy Markdown

Summary

  • Create Slash commands to connect and disconnect.
  • Use twitter OAuth1.0a to allow each user to connect their twitter accounts.

Ticket Link

#6

@chetanyakan
Copy link
Copy Markdown
Author

chetanyakan commented Oct 18, 2020

Screenshots

  1. Slash command responses.

image

  1. OAuth success page.

image

  1. Slash command autocomplete.

image

@hanzei hanzei added the 1: PM Review Requires review by a product manager label Oct 19, 2020
@hanzei hanzei requested a review from levb October 19, 2020 11:55
@hanzei hanzei added the 2: Dev Review Requires review by a core committer label Oct 19, 2020
@levb
Copy link
Copy Markdown
Contributor

levb commented Oct 19, 2020

@chetanyakan @larkox This seems like a perfect application for https://github.com/mattermost/mattermost-plugin-api/tree/master/experimental/oauther. Thoughts?

@levb levb requested a review from larkox October 19, 2020 13:19
@aaronrothschild aaronrothschild requested review from aaronrothschild and removed request for aaronrothschild October 19, 2020 13:46
Copy link
Copy Markdown

@aaronrothschild aaronrothschild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @chetanyakan ! I'll defer to @larkox and @levb on technical implementation but UI so far looks good!

@aaronrothschild aaronrothschild removed the 1: PM Review Requires review by a product manager label Oct 19, 2020
@chetanyakan
Copy link
Copy Markdown
Author

@levb The implementation in experminetal/oather seems to be for OAuth 2.

Twitter uses OAuth 1.0a to allow access to private account information or perform a Twitter action on behalf of a Twitter account and OAuth 2 to access information publicly available on Twitter.

Refer: https://developer.twitter.com/en/docs/authentication/overview

My implementation here is for OAuth 1.0a and is inspired from the of Jira-server OAuth1 implementation.

@levb
Copy link
Copy Markdown
Contributor

levb commented Oct 19, 2020

Thx for clarifying, I commented before I read the code in detail. Let me review now.

@chetanyakan
Copy link
Copy Markdown
Author

@levb @larkox Let me know if you need any help to understand/test this.

Copy link
Copy Markdown

@larkox larkox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment on lines +67 to +74
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()
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check the StatusCode of the response, or that is handled somewhere else?

Comment thread server/util/post.go
ChannelId: channelID,
Message: message,
}
post.SetProps(model.StringInterface{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment thread server/manifest.go
"default": "LwAgBVckO0EQlI2zka55ZFAN16xMRY8T0zvzVI4KbVlCK6tBN1"
},
{
"key": "EncryptionKey",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @larkox. There doesn't seem to be a need to encrypt them.

Copy link
Copy Markdown
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great work 👍

Looking forward on what can be done with this plugin.

Comment thread .gitignore Outdated
# Jetbrains
.idea/

vendor
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vendor?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unresolved

Comment thread go.mod Outdated
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit pick: Please remove the indirect dependencies.

Comment thread plugin.json Outdated
"description": "A Matermost plugin to connect to Twitter.",
"version": "0.1.0",
"min_server_version": "5.12.0",
"min_server_version": "5.27.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What 5.27.0 feature does this plugin use?

Comment thread server/command/twitter.go Outdated
func GetCommand(iconData string) *model.Command {
return &model.Command{
Trigger: "twitter",
DisplayName: "Twitter",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plugin don't need a DisplayName. Mind removing this?

Comment thread server/command/twitter.go

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log the error?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a log in the store method before return.

Comment thread server/store/main.go
return nil
}

func (s Store) StoreTTL(key string, data []byte, ttlSeconds int64) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to get exported?

Comment thread server/store/main.go
return nil
}

func (s Store) StoreWithOptions(key string, value []byte, opts model.PluginKVSetOptions) (bool, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to get exported?

Comment thread server/store/main.go
return success, nil
}

func (s Store) Delete(key string) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to get exported?

Comment thread server/store/ots.go Outdated
if len(data) == 0 {
return ErrNotFound

// TODO: Remove this
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that todo get resolved?

Comment thread server/store/utils.go

// 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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used somewhere?

@hanzei hanzei removed the request for review from levb November 4, 2020 13:04
@hanzei
Copy link
Copy Markdown
Contributor

hanzei commented Nov 10, 2020

/update-branch

@hanzei
Copy link
Copy Markdown
Contributor

hanzei commented Nov 10, 2020

@chetanyakan
Copy link
Copy Markdown
Author

Thanks, @hanzei! I'll pull these changes.

@hanzei hanzei self-requested a review December 16, 2020 14:54
Copy link
Copy Markdown
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the PR! A few things still seem unresolved .

Comment thread .gitignore Outdated
# Jetbrains
.idea/

vendor
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unresolved

Comment thread server/store/main.go
return data, nil
}

func (s Store) Store(key string, data []byte) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems unresolved.

@hanzei hanzei added the Awaiting Submitter Action Blocked on the author label Aug 19, 2021
@hanzei hanzei removed the 2: Dev Review Requires review by a core committer label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting Submitter Action Blocked on the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants