Giphy

Display random GIF in the War Room (e.g. !giphy hello). Powered By Giphy.

Utilities · Giphy

Details

IDGiphy
ProviderShutterstock
CategoryUtilities
From Version5.0.0
Supported ModulesAgentix XSIAM

README

giphy


Display random GIF in the War Room (e.g. !giphy hello)

Base Command

giphy

Input

Argument Name Description Required
tag The GIF tag to limit randomness by. Optional
as-json Returns the response as JSON. Possible values are: true, false. Optional

Context Output

There is no context output for this command.

Configuration parameters

  • url — Giphy URL (required)
  • apikey — API Key
  • apikey_creds

Commands (1)

  • giphy

    Display random GIF in the War Room (e.g. !giphy hello)

var sendRequest = function(tag) {
    var serverUrl = params.url;
    if (serverUrl[serverUrl.length - 1] === '/') {
      serverUrl = serverUrl.substring(0, serverUrl.length - 1);
    }

    var apiKey = params.apikey_creds ? params.apikey_creds.password : params.apikey;
    var requestUrl = serverUrl + '?api_key=' + apiKey + '&tag=' + encodeURIComponent(tag);
    var res = http(requestUrl, { Method: 'GET' });

    if (res.StatusCode < 200 || res.StatusCode >= 300) {
        throw 'Request Failed.\nStatus code: ' + res.StatusCode + '.\nBody: ' + JSON.stringify(res) + '.';
    }

    return JSON.parse(res.Body);
};

// The command input arg holds the command sent from the user.
switch (command) {
    // This is the call made when pressing the integration test button.
    case 'test-module':
        if (sendRequest(tag)) {
            return 'ok';
        }
        return 'not ok';
    case 'giphy':
        var tag = args.tag;
        var asJson = args['as-json'] === 'true';
        var res = sendRequest(tag);

        if (asJson) {
            return res;
        }

        if (res.data && res.data.fixed_height_downsampled_url) {
            var url = res.data.fixed_height_downsampled_url;
            return {
                ContentsFormat: 'markdown',
                Type: 1,
                Contents: '![Giphy ' + tag + '](' + url + ')'
            };
        }

        return 'Nothing found :(';
    default:
        // do nothing
}