public JSONObject post ( String path , JSONObject content , Map < String , String > headers ) throws ServiceException , JSONException { String sub = getSegment ( path , 4 ) ; if ( "event" . equals ( sub ) ) { SlackEvent event = new SlackEvent ( content ) ; EventHandler eventHandler = getEventHandler ( event . getType ( ) , event ) ; if ( eventHandler == null ) { throw new ServiceException ( "Unsupported handler type: " + event . getType ( ) + ( event . getChannel ( ) == null ? "" : ( ":" + event . getChannel ( ) ) ) ) ; } return eventHandler . handleEvent ( event ) ; } else { // action/options request SlackRequest request = new SlackRequest ( content ) ; String userId = getAuthUser ( headers ) ; // TODO: ability to map request.getUser() to corresponding MDW user String callbackId = request . getCallbackId ( ) ; if ( callbackId != null ) { int underscore = callbackId . lastIndexOf ( ' ' ) ; if ( underscore > 0 ) { String handlerType = callbackId . substring ( 0 , underscore ) ; String id = callbackId . substring ( callbackId . lastIndexOf ( ' ' ) + 1 ) ; ActionHandler actionHandler = getActionHandler ( handlerType , userId , id , request ) ; if ( actionHandler == null ) throw new ServiceException ( "Unsupported handler type: " + handlerType ) ; return actionHandler . handleRequest ( userId , id , request ) ; } } throw new ServiceException ( ServiceException . BAD_REQUEST , "Bad or missing callback_id" ) ; } }
Responds to requests from Slack .