@@ -38,17 +38,49 @@ This small app responds to the `/cool` slash command.
3838``` php
3939<?php
4040
41+ use Psr\Log\LogLevel;
4142use SlackPhp\Framework\App;
4243use SlackPhp\Framework\Context;
44+ use SlackPhp\Framework\StderrLogger;
4345use SlackPhp\SocketMode\SocketServer;
4446
4547App::new()
4648 ->command('cool', function (Context $ctx) {
4749 $ctx->ack(':thumbsup: That is so cool!');
4850 })
51+ ->withLogger(new StderrLogger(LogLevel::DEBUG))
4952 ->run(new SocketServer());
5053```
5154
55+ ### Switching Servers
56+
57+ The relationship between app and server can also be flipped, which might be helpful if you bootstrap script toggles
58+ between the Socket and HTTP server.
59+
60+ ``` php
61+ <?php
62+
63+ use Psr\Log\LogLevel;
64+ use SlackPhp\Framework\App;
65+ use SlackPhp\Framework\Context;
66+ use SlackPhp\Framework\Http\HttpServer;
67+ use SlackPhp\Framework\StderrLogger;
68+ use SlackPhp\SocketMode\SocketServer;
69+
70+ $app = App::new()
71+ ->command('cool', function (Context $ctx) {
72+ $ctx->ack(':thumbsup: That is so cool!');
73+ });
74+
75+ if (getenv('SOCKET_MODE')) {
76+ $server = SocketServer::new()->withLogger(new StderrLogger(LogLevel::DEBUG));
77+ } else {
78+ $server = HttpServer::new()->withLogger(new StderrLogger(LogLevel::NOTICE));
79+ }
80+
81+ $server->withApp($app)->start();
82+ ```
83+
5284[ 1 ] : https://github.com/slack-php/slack-php-app-framework
5385[ 2 ] : https://api.slack.com/apis/connections/socket
5486[ 3 ] : https://amphp.org/websocket-client/
0 commit comments