All files / core/blong-gogo/src/adapter/server/slack slackInServer.ts

65.21% Statements 15/23
100% Branches 0/0
100% Functions 0/0
65.21% Lines 15/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 241x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                  
import {handler} from '@feasibleone/blong/types';
 
/**
 * `slackIn.server` — the HTTP answer for a payload that is not processed.
 *
 * Two cases reach here: the `url_verification` challenge, which must be echoed or the app can never
 * be installed, and anything the message hook disowned, which is acknowledged with the configured
 * body. A challenge is the only answer this hook shapes; everything else returns nothing and the
 * receiver's own response is used.
 */
interface IHookContext {
    request: {body?: unknown};
}
 
export default handler(() => {
    return function slackInServer(context: IHookContext) {
        const body = context.request.body as {challenge?: unknown} | undefined;
        if (body && typeof body.challenge === 'string') {
            return {code: 200, body: {challenge: body.challenge}};
        }
        return undefined;
    };
});