https://github.com/doarakko/x-bot-playground
Post to X(Twitter) regularly using Cloudflare.
https://github.com/doarakko/x-bot-playground
cloudflare twitter
Last synced: 2 months ago
JSON representation
Post to X(Twitter) regularly using Cloudflare.
- Host: GitHub
- URL: https://github.com/doarakko/x-bot-playground
- Owner: Doarakko
- License: mit
- Created: 2024-02-23T14:06:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-22T17:50:25.000Z (about 2 years ago)
- Last Synced: 2024-05-01T16:38:10.221Z (about 2 years ago)
- Topics: cloudflare, twitter
- Language: TypeScript
- Homepage:
- Size: 126 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# x-bot-playground
Post to X(Twitter) regularly using Cloudflare.
## Requirements
- Cloudflare
- Twitter Account
- wrangler CLI
- npm
## Usage
1. Clone the repository
```bash
npx wrangler generate x-bot-playground https://github.com/Doarakko/x-bot-playground
npm i
```
1. Configure cron, default is once every hour
`wrandler.toml`
```toml
[triggers]
crons = ["0 * * * *"]
```
1. Deploy to Cloudflare
```bash
wrangler deploy
```
1. Set environmental variables to Cloudflare
```bash
wrangler secret put TWITTER_CONSUMER_API_KEY
wrangler secret put TWITTER_CONSUMER_API_SECRET
wrangler secret put TWITTER_ACCESS_TOKEN
wrangler secret put TWITTER_ACCESS_TOKEN_SECRET
```
## Hints
### Run on local
1. Setup the environment variables
```bash
cp .dev.vars.example .dev.vars
```
1. Run the worker
```bash
wrangler dev
```
### Check if you can post
Remove this comment out and access to your URL.
`src/index.ts`
```typescript
export default {
// async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise {
// const response = await post(env);
// return new Response(JSON.stringify({ status: response.status, message: response.statusText }), {
// headers: { 'Content-Type': 'application/json' },
// });
// },
```
## References
- [Sending a message with the Twitter API in a Cloudflare worker](https://www.leopradel.com/blog/use-twitter-api-clouflare-worker)
- [Cloudflare Docs: Cron Triggers](https://developers.cloudflare.com/workers/configuration/cron-triggers/)