twitter-together / action

:bird: A GitHub action to tweet from a repository
https://github.com/marketplace/actions/twitter-together
MIT License
697 stars 77 forks source link

Creating a twitter poll #79

Closed gr2m closed 4 years ago

gr2m commented 4 years ago

What’s missing?

This is a follow up to https://github.com/processing/p5.js/issues/3893#issuecomment-567193686

Why?

@stalgiag suggested to automate the process of creating twitter polls to generate discussions. Adding that feature to twitter-together will also allow everyone to contribute a twitter poll

Alternatives you tried

Manually creating a pull using twitter.com or one of the apps.

gr2m commented 4 years ago

It looks like creating polls is a bit complicated. It requires that the twitter account is enabled for the Twitter Ads API: https://developer.twitter.com/en/docs/ads/general/overview/adsapi-application

Once that is done, it's a two-step process.

  1. Create a poll card
  2. Create the tweet setting the card_uri parameter to the URI returned by step 1

@stalgiag do you want to get the process going for https://mobile.twitter.com/p5xjs? I'd start by creating a new repository and setting up the action on the @processing org, follow the instructions at https://github.com/gr2m/twitter-together#setup. You will also get the application ID as a result of said setup.

I've submitted https://twitter.com/commit2tweet for testing myself, the automated response is

We will review your application within 1-3 business days. If you do not recieve an email confirming or denying your app's whitelist after 7 days, feel free to contact us at adsapi-program@twitter.com. Please make sure to provide your app ID.

I'll post updates if there are any

gr2m commented 4 years ago

The app currently only supports plain text tweets, no attachments such as images or polls are currently supported. When adding support for polls, I'd also like to think ahead how image attachments would work, as that is a feature I'd like to add in future, too, and I wouldn't want to introduce a breaking change.

I think we can borrow the idea of multipart emails. I do not think that we need a boundary though, separating the parts with just --- and two new lines should be enough. For example

Here is the tweet text

---

( ) Poll option 1
( ) Poll option 2
( ) Poll option 3
( ) Poll option 4

---

https://example.com/url/to/image.jpg

I think the type of attachment can be derived by the content of the part itself.

I'm not yet sure if that format will work with tweet threads, though. Twitter threads are not directly supported, but can be created by creating a separate tweet for each reply and using the in_reply_to_status_id parameter

stalgiag commented 4 years ago

This is exciting @gr2m! It is the beginning of a winter vacation for me soon but I will take care of the setup as soon as possible.

lmccart commented 4 years ago

FYI I started the Twitter Ad API approval process for a @p5xjs app and received a similar message to the one @gr2m posted above. Will keep you updated on this.

stalgiag commented 4 years ago

Finally getting back around to this. Thanks for starting the API approval processing @lmccart

Just to clarify, @gr2m do you think that I should setup a new repository for the @processing org for testing this? I am unsure of what is meant by:

@stalgiag do you want to get the process going for https://mobile.twitter.com/p5xjs? I'd start by creating a new repository and setting up the action on the @processing org

I can add the .yml workflow file to the existing p5 repo (and do the rest of the setup for twitter-together), or I can start a new repo and do this in that repo instead.

Thanks in advance for the clarification!

gr2m commented 4 years ago

Either works. You can set it up for the existing repo https://github.com/processing/p5.js/ repository. The benefit of setting up a separate repository is better control of who can approve tweets, I could imagine these people might be different from the people who can accept pull requests. Do whatever works best for the project

stalgiag commented 4 years ago

Thanks for the clarification!

I believe that either would work. What are your thoughts @lmccart ?

lmccart commented 4 years ago

I think we can integrate directly into the p5.js repo. In general, we try to give as much access as possible to contributors (anyone can get push access to repos, twitter/IG passwords are public, etc). So it probably makes sense to have this directly in the repo just to simplify things.

gr2m commented 4 years ago

Quick update: I received an email from twitter that my test Twitter account @commit2tweet was approved for the Twitter Ads API program. I'll experiment with creating twitter polls this week and will keep you posted here

lmccart commented 4 years ago

I did too! so we can switch to the p5 account anytime it's ready-ish

gr2m commented 4 years ago

There is nothing to switch, I've setup @commit2tweet on this repository, so all *.tweet files merged into https://github.com/gr2m/twitter-together/tree/master/tweets result in a tweet from @commit2tweet. You can already setup twitter-together on the https://github.com/processing/p5.js/ repository for the @p5xjs twitter account, following the instructions at https://github.com/gr2m/twitter-together#setup. Once the feature is ready you'll be able to use it right away, I don't expect any setup changes to be necessary.

lmccart commented 4 years ago

ah, got it, that makes sense. thanks for the clarification!

gr2m commented 4 years ago

Looks like I accidentally submitted an incorrect app ID 🤦‍♂ I'll try to submit again

gr2m commented 4 years ago

I tried to create a poll with the other app that was accidentally approved, but I another error:

User 11754732 is not authorized to make this request. Please have them reauthorize with your client application with id 5728201.

Now I have no idea how to reauthorize an app, and google was not helpful either. I spent way too much time on the mess that is Twitter's APIs & documentation :( I'll wait for them to hopefully come back to me soon. I'll keep you posted here. I hope to get this unblocked soon 🤞

Update: regenerating the keys & tokens worked: https://twittercommunity.com/t/how-to-reauthorize-an-application/133227/2

gr2m commented 4 years ago

Success:

image

I deleted that tweet.

There are still a few things to figure out, but it basically works as I described above: https://github.com/gr2m/twitter-together/issues/79#issuecomment-567889171

My test code for reference ```js const Twitter = require("twitter"); main(); /** * Ads API request don't seem to be implemented in the `twitter` client yet: * https://github.com/desmondmorris/node-twitter/issues/312 * * @see https://ads-api.twitter.com/6/accounts/:account_id/cards/poll */ async function main() { if (!process.env.TWITTER_CONSUMER_KEY) { console.log(`TWITTER_CONSUMER_KEY not set`); return; } const twitter = new Twitter({ consumer_key: process.env.TWITTER_CONSUMER_KEY, consumer_secret: process.env.TWITTER_CONSUMER_SECRET, access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY, access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET }); // get account ID at https://ads.twitter.com/, press on "Go to Twitter Ads", then // copy the part the 2nd segment of the URL path, e.g. // https://ads.twitter.com/onboarding/18ce551qf6o/welcome?onboarding=true => 18ce551qf6o const accountId = "6zy0c"; // Get your Twitter account's user ID at https://codeofaninja.com/tools/find-twitter-id const userId = "11754732"; twitter.post( `https://ads-api.twitter.com/6/accounts/${accountId}/cards/poll`, { name: "foo-bar-1", duration_in_minutes: 120, first_choice: "foo", second_choice: "bar", third_choice: "daz", fourth_choice: "daz" }, (error, result) => { if (error) { console.log(`error`); console.log(error); return; } // result looks like this: // { // request: { // params: { // name: 'foo-bar-1', // first_choice: 'foo', // third_choice: 'daz', // fourth_choice: 'daz', // second_choice: 'bar', // duration_in_minutes: 120 // } // }, // data: { // name: 'foo-bar-1', // start_time: '2020-01-07T22:42:50Z', // first_choice: 'foo', // third_choice: 'daz', // fourth_choice: 'daz', // second_choice: 'bar', // end_time: '2020-01-08T00:42:50Z', // id: '8r115', // created_at: '2020-01-07T22:42:50Z', // duration_in_minutes: '120', // card_uri: 'card://1214678808315351040', // updated_at: '2020-01-07T22:42:50Z', // deleted: false, // card_type: 'TEXT_POLLS' // } // } twitter.post( `https://ads-api.twitter.com/6/accounts/${accountId}/tweet`, { as_user_id: userId, text: "Hey please ignore me, I am just messing with twitter APIs", card_uri: result.data.card_uri, nullcast: false }, (error, result) => { if (error) { console.log(`error`); console.log(error); return; } console.log(`result`); console.log(result); } ); } ); } ```
gr2m commented 4 years ago

I'm still waiting for the approval of the app belonging to @twitter-together :( Let me know if this becomes more urgent for you, I can build it and we can test the new code with p5's twitter account instead.

Do you have any thoughts on the syntax I suggested in https://github.com/gr2m/twitter-together/issues/79#issuecomment-567896037?

lmccart commented 4 years ago

@gr2m thanks for the update, no rush on our end. I think the format looks great.

lmccart commented 4 years ago

you're most welcome to use the p5 account to test though if you're itching to work on it

gr2m commented 4 years ago

Still no update for @twitter-together. I'll just go ahead and build this and use my personal @gr2m account for experimentation as I've an approved app for that.

gr2m commented 4 years ago

Good news, finally got the app for @twitter-together approved. I had to follow up with them per email though, but have been very responsive once I did. I also started working on it at #91

stalgiag commented 4 years ago

Amazing! This is really exciting.

gr2m commented 4 years ago

Sorry that this takes me so long. I'm heads down pushing out a new version of https://github.com/octokit/rest.js/ at work, it takes up all of my time 😭

I'll try to find some today though 🤞 Thanks for bearing with me, I really want to get this done and then build upon it :)

gr2m commented 4 years ago

What would be a good time for twitter polls? It can be anything between 5 minutes and 7 days. I don't want to make it customizable, too complicated. I'd say two days, but please let me know what you think :)

lmccart commented 4 years ago

I agree on not having it customizable. 2 days sounds very reasonable. there is something nice and clean about 1 day, but maybe 2 gives more time/space..

gr2m commented 4 years ago

Yeah let's do one day. I also checked what the default is on twitter.com, and it's 1 day too. We can experiment and change it later as we see fit

lmccart commented 4 years ago

One more thought, apologies if this has already been covered above and I missed it. What do you think about including a link back to the github issue thread? This might invite people to take a peek for more context, or if the poll has closed, they can at least find the thread to comment directly.

gr2m commented 4 years ago

Oh interesting idea! Would it be the URL of the pull request that added the *.tweet file? Or would you have a separate issue discussing the question that you created a poll for on twitter?

I think for now, in both cases, you can just make the URL part of the *.tweet file? We might consider automating it later, or supporting placeholders

lmccart commented 4 years ago

Ohh I didn't realize it was a separate file. I was imagining a scenario where you could directly initiate a poll from an issue, as a way of gathering broader input. But yes, I guess if it's a *.tweet file, then there's no need to build in this link format, one could simply add a link to any relevant issue thread in the body of the tweet message.

gr2m commented 4 years ago

Hm there is also a hack-y way to add embedded polls in GitHub issue directly, maybe that would be of interest?

https://gh-polls.com/

Check the links at the bottom, there are some helpful tools for it.

We could also fairly simply build another custom action that lets you do a comment like

/tweet-poll "option 1" "option 2" "option 3" "option 4"

which in turn would create a pull request with a new *.tweet file (or bypass the PR and create the file directly), which would include a link back to the issue. And once tweeted, the URL to the tweet could be posted back to the thread.

🤷‍♂️ dunno, sounds fun to build, but might be too much?

gr2m commented 4 years ago

Damn I thought I had it, but no luck yet: https://github.com/gr2m/twitter-together/runs/429079950?check_suite_focus=true#step:5:60

I have an idea what it might be, I'll get back to it as soon as possible

gr2m commented 4 years ago

Now that looks promising: https://twitter.com/commit2tweet/status/1225939208650608640

gr2m commented 4 years ago

:tada: This issue has been resolved in version 1.5.3 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

gr2m commented 4 years ago

Can you give it a try?

stalgiag commented 4 years ago

So I think I have everything set up correctly and I committed a new tweet to the tweets folder. It looks like the action was triggered but I am not seeing a tweet.

stalgiag commented 4 years ago

Well actually I am now seeing a 'Resource not accessible by integration' error.

gr2m commented 4 years ago

Hm it's possible that it has something to do with the fact that you ran it on a fork, let me see

gr2m commented 4 years ago

The action was triggered by a pull request. What pull request was that?

I've a check in the code that should avoid trying to create a check run if the PR is coming from a fork, but somehow it didn't do it in your case. I'm a little confused

gr2m commented 4 years ago

Looks like the tweet text is too long:

https://github.com/processing/p5.js/commit/4db6696eab44056df8f8fcdabe4b2f5400ff8d81

Note that updating the *.tweet file will have no effect. I would remove the tweet in master, then in a pull request re-create it. Can you ping me in that PR so I can see if the preview feature is working as it should?

stalgiag commented 4 years ago

Ah yes sorry about that I am twitter naive. I will reopen a pull request but it will have to wait till tomorrow. Thanks for figuring out the problem.

gr2m commented 4 years ago

Ah yes sorry about that I am twitter naive

not at all your fault. Sounds like an opportunity to improve the documentation :)