Created
November 15, 2021 10:15
-
-
Save camrobert/cffde02ac10eef47a7963cdd2b64898c to your computer and use it in GitHub Desktop.
Dad Joke CloudPage SSJS code for Slack API Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
======================================================= | |
Title: Dad Joke CloudPage SSJS code for Slack API Integration. | |
Author: Cameron Robert | |
------------------------------------------------------- | |
Instructions: | |
1: Create a Javascript Code Resource CloudPage | |
2: Paste the below code to the page | |
3: Use the Cloud Page URL as "Request URL" for a "Slash Commands" component in the Slack API Dashboard. | |
4: Save and Authorise your Slack app to a workspace/channel, and use the Slash Command to interact | |
======================================================= | |
*/ | |
<script runat="server"> | |
Platform.Load("Core","1"); | |
try { | |
var response = HTTP.Get('http://icanhazdadjoke.com/',['Accept'], ['application/json']); //GET request to the Dad Joke API | |
var json = Platform.Function.ParseJSON(response.Content); //Parse the response to JSON | |
Write(json.joke); //Output the Joke object in the JSON | |
} | |
catch(error) { | |
Write('Message: '+ error); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment