Chat is more social with GIFs. GIPHY APIs help you integrate the world's largest GIF library, customize a suite of powerful features, and boost engagement with just a few lines of code.
With PubNub Functions, use a pre-built Block that integrates with GIPHY to let users send each others GIFs in a chat message based on the text it reads in the message, as you would do in an app like Slack.
Some Blocks require third-party service signup
When Blocks integrate with third-party services, such as Amazon, Librato, MapBox, or RingCentral, the services often require account setup to use them. Please make sure to visit each Block's documentation page, located in the Blocks Catalog, to learn what's required.
GIPHY Function Code
Setting up the Function
Create a new function. Go to your PubNub Dashboard and create a new module, and then create a new Before Publish function. The function should be set up to trigger on a specific set of channels (such as
chat.*) or on all channels using wildcards (
Copy the function code from above. You'll need to update the API key for the service from your account.
Click Start module to start the function, and test it using the Test Payload field and Publish button on the left.
Testing the Function
Input: A JSON object containing key "text", with the message needs to be published on input channel. If message contains /gif tag, then the next word will be used for finding a matching GIF image. Multiple tags can exist in the same message. To include GIF URLs based on phrases or sentences, enclose them using parentheses:
Output: The modified message containing the list of GIF URLs is received on same channel.