{"id":19456393,"url":"https://github.com/slack-php/slack-php-socket-mode","last_synced_at":"2025-04-25T05:31:00.985Z","repository":{"id":57053022,"uuid":"378700085","full_name":"slack-php/slack-php-socket-mode","owner":"slack-php","description":"A Socket Mode implementation for the slack-php framework","archived":false,"fork":false,"pushed_at":"2022-11-12T00:22:49.000Z","size":29,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-04-13T02:06:48.973Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/slack-php.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":"2021-06-20T17:12:12.000Z","updated_at":"2024-10-09T10:37:46.000Z","dependencies_parsed_at":"2023-01-21T16:15:30.960Z","dependency_job_id":null,"html_url":"https://github.com/slack-php/slack-php-socket-mode","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/slack-php%2Fslack-php-socket-mode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-php%2Fslack-php-socket-mode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-php%2Fslack-php-socket-mode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/slack-php%2Fslack-php-socket-mode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/slack-php","download_url":"https://codeload.github.com/slack-php/slack-php-socket-mode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250760672,"owners_count":21482847,"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-11-10T17:17:02.631Z","updated_at":"2025-04-25T05:31:00.647Z","avatar_url":"https://github.com/slack-php.png","language":"PHP","funding_links":[],"categories":[":hammer_and_wrench: \u0026nbsp; Libraries and SDKs"],"sub_categories":["PHP"],"readme":"# Slack PHP – Socket Mode\n\nThis package provides a slack-php `AppServer` implementation that allows an application written for the\n[Slack App Framework for PHP][1] to be run in [Socket Mode][2]. Socket Mode uses the websocket protocol to communicate\nwith Slack, and allows you to run an app (even locally) without having to expose it via a public HTTP endpoint. This can\nbe very useful for testing Slack apps in a way that does not violate most work-related firewall restrictions.\n\n**This package should be used for testing only, and is not designed for production use.**\n\n\u003e This Socket Mode implementation uses the [`amphp/websocket-client`][3] package from [Amp][4], an awesome collection of\nPHP packages that make async and event loop style programming in PHP possible. Check it out sometime.\n\n## Installation\n\n- Requires PHP 7.4+\n- Use Composer to install: `composer require slack-php/slack-socket-mode`\n\n## Usage\n\nWhen using Socket Mode, there is no web server serving your app. When you run an app configured for Socket Mode, it\nestablishes a connection to Slack as a websocket client. It maintains that connection to listen for Slack events until\nit is explicitly terminated (e.g., via `CTRL+C`), Socket Mode is disabled in your app configuration, or an unrecoverable\nerror occurs. This is a different way of running PHP than many aren't used to, so please pay close attention.\n\nWhen running an app in Slack Mode, you need an \"App Token\" instead of the typical \"Signing Secret\". The App Token is\nspecially purposed for making the web socket connection. You can read more about [Socket Mode][2] in the Slack\ndocumentation to learn how to get an App Token.\n\n### Example\n\nThis small app responds to the `/cool` slash command.\n\n\u003e Assumptions:\n\u003e\n\u003e - You have required the Composer autoloader to enable autoloading of the framework files.\n\u003e - You have set `SLACK_APP_TOKEN` in the environment (e.g., `putenv(\"SLACK_APP_TOKEN=foo\");`)\n\n```php\n\u003c?php\n\nuse Psr\\Log\\LogLevel;\nuse SlackPhp\\Framework\\{App, Context, StderrLogger};\nuse SlackPhp\\SocketMode\\SocketServer;\n\nApp::new()\n    -\u003ecommand('cool', function (Context $ctx) {\n        $ctx-\u003eack(':thumbsup: That is so cool!');\n    })\n    -\u003ewithLogger(new StderrLogger(LogLevel::DEBUG))\n    -\u003erun(new SocketServer());\n```\n\n### Switching Servers\n\nThe relationship between app and server can also be flipped, which might be helpful if you bootstrap script toggles\nbetween the Socket and HTTP server.\n\n```php\n\u003c?php\n\nuse Psr\\Log\\LogLevel;\nuse SlackPhp\\Framework\\{App, Context, StderrLogger};\nuse SlackPhp\\Framework\\Http\\HttpServer;\nuse SlackPhp\\SocketMode\\SocketServer;\n\n$app = App::new()\n    -\u003ecommand('cool', function (Context $ctx) {\n        $ctx-\u003eack(':thumbsup: That is so cool!');\n    });\n\nif (getenv('SOCKET_MODE')) {\n    $server = SocketServer::new()-\u003ewithLogger(new StderrLogger(LogLevel::DEBUG));\n} else {\n    $server = HttpServer::new()-\u003ewithLogger(new StderrLogger(LogLevel::NOTICE));\n}\n\n$server-\u003ewithApp($app)-\u003estart();\n```\n\n[1]: https://github.com/slack-php/slack-php-app-framework\n[2]: https://api.slack.com/apis/connections/socket\n[3]: https://amphp.org/websocket-client/\n[4]: https://amphp.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslack-php%2Fslack-php-socket-mode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fslack-php%2Fslack-php-socket-mode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fslack-php%2Fslack-php-socket-mode/lists"}