Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PubNub Q&A BLOCK w/ Wolfram Alpha API
const xhr = require('xhr');
const query = require('codec/query_string');
export default (request) => {
const appId = 'YOUR_WOLFRAM_ALPHA_APP_ID';
const spoken = 'http://www.wolframalpha.com/api/v1/spoken-json.jsp';
const queryParams = {
appid: appId,
input: request.message.text
};
const apiUrl = spoken + '?' + query.stringify(queryParams);
return xhr.fetch(apiUrl)
.then((r) => {
const body = JSON.parse(r.body || r);
request.message.answer = body.result || body.error;
return request.ok();
})
.catch((e) => {
console.error(e);
return request.ok();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment