{"id":25974969,"url":"https://github.com/pjc0247/slacker2","last_synced_at":"2025-03-05T02:36:10.019Z","repository":{"id":37932732,"uuid":"78389001","full_name":"pjc0247/Slacker2","owner":"pjc0247","description":"Slackbot framework, C#","archived":false,"fork":false,"pushed_at":"2022-06-22T17:42:20.000Z","size":93,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-02T20:52:12.517Z","etag":null,"topics":["bot","slack","slackbot"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pjc0247.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":"2017-01-09T03:07:11.000Z","updated_at":"2019-09-17T08:57:21.000Z","dependencies_parsed_at":"2022-08-25T22:24:26.742Z","dependency_job_id":null,"html_url":"https://github.com/pjc0247/Slacker2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjc0247%2FSlacker2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjc0247%2FSlacker2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjc0247%2FSlacker2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pjc0247%2FSlacker2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pjc0247","download_url":"https://codeload.github.com/pjc0247/Slacker2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241954950,"owners_count":20048402,"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":["bot","slack","slackbot"],"created_at":"2025-03-05T02:36:09.514Z","updated_at":"2025-03-05T02:36:10.009Z","avatar_url":"https://github.com/pjc0247.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"Slacker2\n====\n\n__Create your own Slackbot w/ C#.__\u003cbr\u003e\n\u003cbr\u003e\n\nQuick Guide\n---\n__Initialization__ \n```cs\nSlackBot.Configuration = new SlackBotConfiguration()\n{\n    AuthToken = \"xoxb-AAAA-BBBBBBBB\"\n};\nSlackBot.Run();\n\n// `SlackBot.Run` does not block the program.\n// You have to hold your bot yourself.\nConsole.ReadLine();\n```\nYou can find your AuthToken [here](https://api.slack.com/docs/oauth-test-tokens).\n\n__Respond to messages__\u003cbr\u003e\nCreating a new bot command is very simple. Even you don't need to register your commands manually.\u003cbr\u003e\nJust define a method and let __Slacker2__ know the method is a subscriber. __Slacker2__ will find all your subscribers automatically.\u003cbr\u003e\n\u003cbr\u003e\nThe example below shows that how to make a basic bot command.\n```cs\npublic class Program : BotService {\n\n    // put a regular expr which you want to subscribe\n    [Subscribe(\"^hello\")]\n    public void OnHello(SlackMessage message) {\n        message.Reply(\"hi there\");\n    }\n}\n```\n\n__Accept command parameters__\u003cbr\u003e\nSince `Subscribe` attribute accepts a regular expressions, you can also use `capturing` function.\u003cbr\u003e\nCaptured values will be bound to method's parameters in order.\n```cs\n[Subscribe(\"^echo (.+)$\")]\npublic void OnEcho(SlackMessage message, string echo) {\n    message.Reply(echo);\n}\n\n[Subscribe(\"^sum (.+) (.+)$\")]\npublic void OnSum(SlackMessage message, int a, int b) {\n    message.Reply($\"{a} + {b} = {a + b}\");\n}\n```\n\n\n__Periodic tasks__\u003cbr\u003e\nIf you need to execute a method in every specific minutes, just add a `Schedule` attribute on your method.\u003cbr\u003e\n__Slacker2__ will invoke the method repeatedly by internally managed timers.\n```cs\n[Schedule(1)] // interval (seconds)\npublic void OnTimer()\n{\n    Console.WriteLine(\"Minsoo chunjaeya\");\n}\n```\n\nInteractive Message\n----\n```\nCurrently, Slacker2 only supports `buton` type messages.\n```\n__Requirements__\u003cbr\u003e\n__Slack__ requires a __https__ server for interactive messages. we detour this using `AWS.SQS` and `AWS.Labmda`.\u003cbr\u003e\n```\nTODO\n```\n\nIf you can manage a __https__ server yourself, you may want to use it without AWS stuffs.\u003cbr\u003e\nHowever, We don't have flexibilities for it. You have to implement by yourself.\u003cbr\u003e\n__[Please edit these lines of code](https://github.com/pjc0247/Slacker2/blob/master/Slacker2/SlackService.cs#L191-L204)__\n\n__Send a message that includes some buttons__\n```cs\nvar choice = await SendActionMessageAndWait(\n    \"channel\", \"choose one of the following items\",\n    new SlackInteractiveMessage() {\n        Buttons = new SlackActionButton[] {\n            new SlackActionButton() {\n                Name = \"orange\", Text = \"Give me an Orange!\"\n            },\n            new SlackActionButton() {\n                Name = \"banana\", Text = \"Give me a Banana!\"\n            }\n        }\n    });\n    \nif (choice == \"orange\") { /* ... */ }\nelse if (choice == \"banana\") { /* .... */ }\n```\n\nAdvanced Features\n----\n__User permission__\u003cbr\u003e\nSometimes, you may want to make dangerous functions. Such as changing machine's state or handling your private data.\u003cbr\u003e\n__Slacker2__ also provides a permission management feature. You can add the required permissions on your commands and __grant__/__remove__ each permissions to the right users.\n\n```cs\n[Subscribe(\"^!sys_shutdown$\")]\n[NeedsPermission(\"SYSTEM_SHUTDOWN\")]\npublic void OnShutdown(SlackMessage message) {\n    /* shutdown machine */\n}\n```\n```cs\nGrantPermission(user, \"SYSTEM_SHUTDOWN\");\n// now `user` can invoke `!sys_shutdown` method.\n```\n\nUser permissions can be evaluated at method's body instead `NeedsPermission` attribute. \n```cs\nvar user = message.Sender;\n\nif (user.Permissions.Contains(\"SYSTEM_SHUTDOWN\"))\n    ; /* shutdown machine */\nelse\n    message.Reply(\"Sorry, but you don't have the proper permission.\");    \n```\n\n\nIntegrations w/ Slacker2\n----\n* [AWS.CloudWatch](https://github.com/pjc0247/Slacker2.CloudWatcher)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpjc0247%2Fslacker2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpjc0247%2Fslacker2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpjc0247%2Fslacker2/lists"}