Hire 
Denys Linkov
Submit
Note: Voiceflow is not responsible for the exchange of services between you and the partner.
Thank you! An email will be sent connecting you with the expert.
Oops! Something went wrong while submitting the form.

Search and retrieve a GIF from GIPHY

Template
Function
21
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.

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.