This repository has been archived by the owner on Dec 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
executable file
·63 lines (46 loc) · 1.8 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Main entry point for Slackemon requests made by Slack.
*
* @package Slackemon
*/
// Before starting, determine if we're receiving an inbound action or option request from our Slack app.
$payload = json_decode( file_get_contents( 'php://input' ) );
if ( ! $payload && isset( $_REQUEST['payload'] ) ) {
$payload = json_decode( $_REQUEST['payload'] );
}
if ( $payload ) {
// Action, or message menu options request?
if ( isset( $payload->actions ) && count( $payload->actions ) ) {
// Set up Slackemon environment.
$action = $payload;
require_once( __DIR__ . '/lib/init.php' );
// Handle the action in the background.
$callback_id = $action->callback_id;
slackemon_run_background_action( 'src/_actions.php', $action, $callback_id );
return slackemon_exit();
} elseif ( isset( $payload->action_ts ) && isset( $payload->callback_id ) ) {
// Set up Slackemon environment.
$options_request = $payload;
require_once( __DIR__ . '/lib/init.php' );
// Prepare for JSON output, which will happen within our request handler.
header( 'Content-Type: application/json' );
// Handle the options request.
$options = slackemon_get_slack_message_menu_options( $options_request->name, $options_request->value );
if ( $options ) {
echo $options;
}
return slackemon_exit();
}
}
// Otherwise, let's get going - no-one will get past here now unless they're authorised with a Slack App token.
require_once( __DIR__ . '/lib/init.php' );
// Init the once-off, entry-point stuff.
if ( ! defined( 'COMMAND' ) ) {
define( 'COMMAND', $_POST['command'] );
}
// Run as a background command, as long as this isn't a test run.
$args = check_subcommands();
slackemon_run_background_command( 'src/_commands.php', $args );
return slackemon_exit();
// The end!