- Setup a Twitter Developer account, you can follow the instructions down here
- Create a new project with a new app in the Twitter developer portal
- Clone this repository, or create your own repo using this as a template
- Create a
.env
file and fill it out with tokens & keys from your Twitter dev account (use the provided.env-example
file as a reference) - From the base directory, run
npm install
to install the necessary packages - Also from the base directory, run
node index.js
to run the script and send a tweet - Add some of your own logic in the
handleTweet()
function and test it out!
-
Push your newly created repository to a remote Github repo
-
Add the environment variables securely
- On your repository page on Github, select the Settings tab
- On the left side under the Security header, open the Secrets dropdown and select Actions
- Select the green "New repository secret" button
- For the Name, enter
ENV_FILE
- For the Secret, paste the exact contents of your local
.env
file (don't worry, it's secure)
- Select the green "Add secret" button
-
Create a Github Action (if you're already familiar with Github Actions, skip to step 5 for the yml code)
- On your repository page on Github, select the Actions tab
- On the left side, select the "New workflow" button
- At the top, under the "Choose a workflow" header, select the blue link which says "set up a workflow yourself"
- You're now creating a new file, you can leave the name as the default
main.yml
- For the content of the file, paste the following code:
name: send-tweet on: workflow_dispatch jobs: tweet: runs-on: ubuntu-latest strategy: matrix: node-version: [16.x] steps: - uses: actions/checkout@v3 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm i - run: echo "${{ secrets.ENV_FILE }}" > .env - run: node index.js
- In the top right, select "Start commit", and then "Commit new file"
-
Run your Github Action
- Create new twitter account for your bot
- Head to https://developer.twitter.com
- Sign up button
- In the "What's your use case?" section, select "Making a bot" and Continue
- Verify your email
- Enter a name for your app
- Write all of the secrets and keys down! These are used in your
.env
file - Continue to the Dashboard