Ask — API Configuration
Choose which articles Ask can cite in its answers, and change the response before Ask shows it.
useApi takes the request body that Ask sends to the
Answer API. The question comes from the reader, and the
other fields control the answer.
Filter the source articles
fq restricts which articles an answer can cite. It takes the same
filter syntax as every other Miso endpoint.
Set it on client.ui.asks, the context that covers every Ask workflow on the
page. Each follow-up answer is a new workflow, so a filter on client.ui.ask
does not reach it.
client.ui.asks.useApi({
fq: 'categories:"Markets"',
});
Filter values are matched exactly. Check yours against the rules for case and quoting.
To change the filter while the page runs, see Filtering (fq).
Change the response
useDataProcessor takes a function that gets each response before Ask renders
it. data.value holds the Answer API response, with
answer, sources and the other fields. Return data, changed or not.
Set it on client.ui.asks, so that follow-up answers get it too. This one
takes the site name off the end of each source title:
client.ui.asks.useDataProcessor((data) => {
const { value } = data;
if (!value || !value.sources) {
return data;
}
return {
...data,
value: {
...value,
sources: value.sources.map((source) => ({
...source,
title: source.title.replace(/ \| Example News$/, ""),
})),
},
};
});
The SDK calls the function each time the data changes. Before the response
arrives, data.value is undefined, and while the answer streams in, the function runs again on each new part. Check for the field you
change, and return data as it is when the field is missing.
Each call to useDataProcessor adds a function, and the functions run in the
order you add them. clearDataProcessor() removes the ones added on the same
object.
