Request offers from Dialogflow¶
A Dialogflow ES agent can show Offer Manager offers by calling the Fetch API from its fulfillment webhook. The Fetch API renders the offer as a Dialogflow Card message, which the webhook appends to the intent's response. This document describes how to make the call and map intents to moments. For the request in general, see Request an offer.
Before you begin¶
- Create a moment for each intent that should be able to show an offer, and a rule with at least one offer for it.
- Get an API key from API Keys in the console's account menu, and store
it in your webhook's environment as
ADCHAT_API_KEY. Store the ID of the agent your moments belong to asADCHAT_APPLICATION. - Your agent must have a fulfillment webhook that you control.
Map intents to moments¶
Use each intent's action value as the code of its moment. For example,
the Default Welcome Intent has the action input.welcome. Create a moment
with the code input.welcome, and your webhook can pass the action through
as the moment's code. Each intent then has its own rules, offers, and
reports.
Call the Fetch API from the webhook¶
-
In your webhook, when it handles an intent, request an offer with
format=dialogflowand the intent's action asadUnit:const axios = require('axios'); async function fetchOffer(action, sessionId) { const response = await axios.post( 'https://ads.advertising.chat/v1/fetch/v2', {}, { params: { key: process.env.ADCHAT_API_KEY, application: process.env.ADCHAT_APPLICATION, adUnit: action, format: 'dialogflow', subscriber: sessionId, }, validateStatus: status => status === 200 || status === 204, } ); return response.status === 200 ? response.data : null; } -
If the function returns an offer, append
offer.payloadto thefulfillmentMessagesof the webhook response, after the intent's own messages. The payload has this shape: -
If the function returns
null, send the intent's own messages only. No offer fits this moment, which is the common case. - Keep
offer.messageIdwith the session if you report conversions later. See Report what happens.
Card buttons carry the offer's Navigate actions as click-tracking URLs, so taps are recorded automatically.
Test the integration¶
In the Dialogflow console, use the Try it now panel to trigger an intent
that your webhook handles. When the integration works, the offer's card
appears after the intent's response. If no card appears, add test: 1 to
the request parameters and read disqualifications in the response.
What's next¶
- Review performance for each intent's moment.
- Read every request parameter in the Fetch API reference.
- Read how rules are evaluated in Moments, offers, and rules.