Search and retrieve a GIF from GIPHY

Template
Function
1
Template
Function
by
Denys Linkov

Searches Giphy for gifs matching the specified searchTerm with a given language.

Created:

Heading

Voiceflow APIs used:

Channels
No items found.
Created By
Denys Linkov
This is some text inside of a div block.
Overview
This is some text inside of a div block.
by
This is some text inside of a div block.

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Block quote

Ordered list

  1. Item 1
  2. Item 2
  3. Item 3

Unordered list

  • Item A
  • Item B
  • Item C

Text link

Bold text

Emphasis

Superscript

Subscript

Heading
Based in
This is some text inside of a div block.
Heading

Function Code Snippet


export default async function main(args) {
let { language, searchTerm, apiKey, limit } = args.inputVars;

try {
if (!language) { language = 'en' }
if (!searchTerm) { throw new Error("missing a value for `searchTerm`"); }
if (!apiKey) { throw new Error("missing API key"); }
if (!limit) { limit = 1; }
} catch (err) {
return {
next: {
path: 'Error_Fetching'
},
trace: [
{
type: "debug",
payload: {
message: `Could not search for a .gif, ${err.message}`
}
}
]
};
}

const apiUrl = `https://api.giphy.com/v1/gifs/search?api_key=${apiKey}&q=${searchTerm}&limit=${limit}&lang=${language}`;
const response = await fetch(apiUrl);
const responseBody = response.json;
return {
next: {
path: 'Success'
},
trace: responseBody.data.map(properties => ({
type: "cardV2",
payload: {
imageUrl: properties.images.fixed_height.url,
title: properties.title,
description: {
text: properties.title,
}
}
}))
};
}
copy-icon

Explore More Templates

Build and submit a Template to have it featured in the community.

ghraphic
No items found.
No items found.