| 1 |
import { Axios as api, restApi, wpHeaders } from './axios' |
| 2 |
|
| 3 |
// Optionally add items to request body |
| 4 |
const denyList = ['nonce', 'api'] |
| 5 |
const extraBody = { |
| 6 |
...Object.fromEntries( |
| 7 |
Object.entries(window.extChatData).filter( |
| 8 |
([key]) => !denyList.includes(key), |
| 9 |
), |
| 10 |
), |
| 11 |
} |
| 12 |
|
| 13 |
export const getAnswer = ({ question, experienceLevel }) => |
| 14 |
fetch(`${window.extChatData.api}/ask-question`, { |
| 15 |
method: 'POST', |
| 16 |
headers: { |
| 17 |
'Content-Type': 'application/json', |
| 18 |
}, |
| 19 |
body: JSON.stringify({ question, experienceLevel, ...extraBody }), |
| 20 |
}) |
| 21 |
|
| 22 |
export const rateAnswer = ({ answerId, rating }) => |
| 23 |
fetch(`${restApi}/chat/rate-answer`, { |
| 24 |
method: 'POST', |
| 25 |
headers: wpHeaders, |
| 26 |
body: JSON.stringify({ answerId, rating }), |
| 27 |
}) |
| 28 |
|
| 29 |
export const getOptions = () => api.get('chat/options') |
| 30 |
|
| 31 |
export const updateOptions = (options) => api.post('chat/options', { options }) |
| 32 |
|
| 33 |
export const updateUserMeta = (user, option, value) => |
| 34 |
api.post('draft/update-user-meta', { user, option, value }) |
| 35 |
|