{"id":16133734,"url":"https://github.com/futuresharks/serverless-twitter-bot","last_synced_at":"2025-03-18T15:31:00.860Z","repository":{"id":43149618,"uuid":"350261044","full_name":"FutureSharks/serverless-twitter-bot","owner":"FutureSharks","description":"A Python Twitter bot that runs on AWS Lambda (or locally)","archived":false,"fork":false,"pushed_at":"2023-10-04T00:52:52.000Z","size":1350,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T10:33:09.233Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FutureSharks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-22T08:17:12.000Z","updated_at":"2024-03-16T14:02:22.000Z","dependencies_parsed_at":"2024-10-27T18:21:04.751Z","dependency_job_id":"b2b30957-ee40-4dfd-ad7d-6225f9b143bf","html_url":"https://github.com/FutureSharks/serverless-twitter-bot","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FutureSharks%2Fserverless-twitter-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FutureSharks%2Fserverless-twitter-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FutureSharks%2Fserverless-twitter-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FutureSharks%2Fserverless-twitter-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FutureSharks","download_url":"https://codeload.github.com/FutureSharks/serverless-twitter-bot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243933428,"owners_count":20370989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T22:45:33.999Z","updated_at":"2025-03-18T15:31:00.451Z","avatar_url":"https://github.com/FutureSharks.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# serverless-twitter-bot\n\n[![](img/aws-lambda-logo.jpg)](#) [![](img/twitter-logo.png)](#)\n\nA Twitter bot written in Python that runs on AWS Lambda. The bot has a number of functions, called \"modes\", that can do the following actions:\n\n- Like tweets from a list of users\n- Retweet tweets from a list of users\n- Reply with text randomly chosen from a list\n- Reply with images randomly chosen from a list\n- And more in [serverless_twitter_bot/bot_functions](serverless_twitter_bot/bot_functions)\n\nOther features:\n\n- Easy to add new modes for different functionality or behaviour\n- Bot state is saved to an S3 bucket\n- Images used in replies can be stored on S3 or locally\n- Mode can save their own state to persist data after each run\n- Rate limiting for the bot, per mode or per user interaction\n- Can also just be run locally\n- Written in Python 3\n- Detailed logging\n\nYou will need to [create a Twitter developer account](https://developer.twitter.com/en/apply-for-access) and create a twitter application.\n\nExample bot configuration:\n\n```yaml\nname: my-bot\n\nmodes:\n  reply_to_friends:\n    function: reply\n    config:\n      tweets:\n        - 100% agree 💙\n        - I miss you\n    recipients:\n      - BoJackHorseman\n\n  like_tweets:\n    function: like\n    recipients:\n      - NASAPersevere\n      - archillect\n      - horse_ebooks\n    rate_limit:\n      type: per_recipient\n      time: 2d\n\n  retweet:\n    function: retweet\n    recipients:\n      - dril\n      - Coldwar_Steve\n    rate_limit:\n      type: per_recipient\n      time: 3d\n\n  reply_to_idiots:\n    function: reply\n    config:\n      tweets:\n        - Are your parents cousins?\n        - You are an embarrassment\n    recipients:\n      - DonaldJTrumpJr\n```\n\n## Installation and configuration\n\nConfiguration of the modes, rate limiting and other settings is in a simple YAML file. It's easiest to just look at the example: [terraform/bot-config.yaml](terraform/bot-config.yaml).\n\nTo create the AWS Lambda function and all associated resources it's easiest to use the provided Terraform code in [terraform](terraform).\n\n## Running\n\nSome environment variables are required for configuration of the bot:\n\n- `BOT_CONFIG_FILE`: Path to the bot configuration file\n- `STATE_S3_BUCKET`: The name of the S3 bucket to find/store the bot state\n- `STATE_S3_KEY`: The name of the key in the S3 bucket to find the state file\n- `AWS_REGION`: The AWS region\n- `TWITTER_CONSUMER_KEY`, `TWITTER_CONSUMER_SECRET`, `TWITTER_ACCESS_TOKEN`, `TWITTER_ACCESS_TOKEN_SECRET`: These come from your Twitter app in the [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard)\n\n### Locally\n\nInstall the required packages:\n\n```\npip3 install -r requirements.txt\n```\n\nYou can run it locally without AWS Lambda like this:\n\n```\npython3 main.py\n```\n\nYou can also install it locally:\n\n```\npip3 install .\n```\n\n### Manually using AWS CLI\n\nRun this:\n\n```\naws lambda invoke --function-name my-bot-name out --log-type Tail --query 'LogResult' --output text |  base64 -d\n```\n\n### Manually using AWS Console\n\nYou can run a test invocation from the AWS Lambda console tab `Test`, the payload doesn't matter.\n\n### On a schedule\n\nThe Terraform code has a `enable_schedule` variable to enable a schedule for running the AWS Lambda function.\n\n## Running tests\n\nTo run all tests, from root of repo run:\n\n```\npython3 -m unittest discover\n```\n\nOr to run a specific tests:\n\n```\npython3 -m unittest tests.test_bot.TestBot\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturesharks%2Fserverless-twitter-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuturesharks%2Fserverless-twitter-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturesharks%2Fserverless-twitter-bot/lists"}