{"id":27262262,"url":"https://github.com/brandenc40/groupme-bot","last_synced_at":"2025-04-11T05:49:43.956Z","repository":{"id":55442527,"uuid":"323495260","full_name":"brandenc40/groupme-bot","owner":"brandenc40","description":"Easily build one or more bots into a single application. Supports regex handlers of incoming messages as well as cron jobs to perform functions on a regular cadence. ","archived":false,"fork":false,"pushed_at":"2023-06-24T05:47:37.000Z","size":109,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-11T05:49:39.965Z","etag":null,"topics":["apscheduler","bot","builder","chatbot","cron","flask","groupme","pypi","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/groupme-bot/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brandenc40.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}},"created_at":"2020-12-22T02:05:08.000Z","updated_at":"2022-09-08T21:16:00.000Z","dependencies_parsed_at":"2022-08-15T00:20:51.612Z","dependency_job_id":null,"html_url":"https://github.com/brandenc40/groupme-bot","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandenc40%2Fgroupme-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandenc40%2Fgroupme-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandenc40%2Fgroupme-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brandenc40%2Fgroupme-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brandenc40","download_url":"https://codeload.github.com/brandenc40/groupme-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351430,"owners_count":21089271,"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":["apscheduler","bot","builder","chatbot","cron","flask","groupme","pypi","python"],"created_at":"2025-04-11T05:49:43.305Z","updated_at":"2025-04-11T05:49:43.884Z","avatar_url":"https://github.com/brandenc40.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GroupMe Bot Builder\n\n#### Easily build one or more bots into a single application. Supports regex handlers of incoming messages as well as cron jobs to perform functions on a regular cadence.\n\n\n```\npip install groupme-bot\n```\n\n## Usage\n\n- An Application object is created to house one or many Bot objects and route incoming traffic to the correct Bot. Each Bot is registered at it's own url path\nto allow for Bots to easily setup callbacks in the GroupMe Developer site.\n- A separate Bot object is defined for each bot and can include the following handlers:\n    - Regexp Handlers: If a message is sent to the group that matches the given regex, the associated handler function will be called\n    - Cron Jobs: Handler functions that will be run on a set cron cadence\n- Handler functions all take one argument (context) which is of type Context. The Context contains both a reference to the Bot object being called and the Callback object containing the payload from GroupMe.\n    - The passing of the Bot object in the Context allows for handler functions to be universal and shared by multiple Bots.\n    \n### Running Your App\n\nStart your app with [Uvicorn](http://www.uvicorn.org/deployment/). For more deployment details, see http://www.uvicorn.org/deployment/.\n\nExample running an `app` object in `main.py`.\n\n**Must use `--workers=1` to prevents scheduled jobs from running multiple times. Working on a fix for this.**\n\n```\nuvicorn main:app --workers=1\n```\n\n### Multi Bot Example\n\n```python\n# main.py\n\nimport re \n\nfrom groupme_bot import Application, Bot, Context, ImageAttachment, LocationAttachment\n\n\n# create the bot Application\napp = Application()\n\n\n# define handler functions\ndef cron_task(ctx: Context):\n    print(ctx.bot.bot_name)\n    print(\"this is a scheduled function at the top of every hour\")\n\ndef mention_all(ctx: Context):\n    ctx.bot.mention_all()\n    \ndef attachments(ctx: Context):\n    img_url = ctx.bot.image_url_to_groupme_image_url(image_url=\"https://images.indianexpress.com/2020/12/Doodle.jpg\")\n    image_attachment = ImageAttachment(image_url=img_url)\n    location_attachment = LocationAttachment(name=\"A Location\", lat=100.000, lng=46.000)\n    ctx.bot.post_message(\"this is a message with attachments\", [image_attachment, location_attachment])\n\ndef gif_search(ctx: Context):\n    sr = re.search(r'^\\\\gif([a-zA-Z0-9 -_]+)', ctx.callback.text)\n    if sr:\n        query_string = sr.group(1).strip()\n        # gif_result = search_for_gif(query_string)\n        # ctx.bot.post_message(gif_result)\n        print(\"implement something like this ^\")\n\n\n# build the bot objects\nbot1 = Bot('Fake bot 1',\n           bot_id='fake-bot-id',\n           groupme_api_token='fake-token',\n           group_id='fake-group-id')\n\nbot2 = Bot('Fake bot 2',\n           bot_id='fake-bot-id',\n           groupme_api_token='fake-token',\n           group_id='fake-group-id')\n\n# add cron job\n#  - available cron_task arguments: https://apscheduler.readthedocs.io/en/stable/modules/triggers/cron.html\nbot1.add_cron_job(cron_task, minute=0, hour='*', timezone='America/Chicago')\n\n# add callback handlers\nbot1.add_callback_handler(r'^\\\\attachments', attachments)  # message starts with the string '\\attachments'\nbot1.add_callback_handler(r'^\\\\all', mention_all)  # message starts with the string '\\all'\nbot2.add_callback_handler(r'^\\\\all', mention_all)  # message starts with the string '\\all'\nbot2.add_callback_handler(r'^\\\\gif', gif_search)  # message starts with the string '\\gif'\n\n\n# add the bots to the bot router\napp.add_bot(bot=bot1, callback_path=\"/bot1\")\napp.add_bot(bot=bot2, callback_path=\"/bot2\")\n\n# to run:\n# `uvicorn main:app --workers=1`\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandenc40%2Fgroupme-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrandenc40%2Fgroupme-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrandenc40%2Fgroupme-bot/lists"}