Node.js 无法导出连接
我正在创造一种在Salesforce平台上工作的技能。我用图书馆来做这件事 情况就是这样 我有两个文件Node.js 无法导出连接,node.js,json,Node.js,Json,我正在创造一种在Salesforce平台上工作的技能。我用图书馆来做这件事 情况就是这样 我有两个文件 index.js restServices.js 我想将我的rest端点操作分离到第二个文件中,在处理请求后只留下响应作为索引。我做了账户链接,效果很好。我正在使用下面的代码建立连接(Alexa应用程序上的oAuth认证后),如前所述。这是我的密码 function onLaunch(launchRequest, session, response) { if (!session.us
function onLaunch(launchRequest, session, response) {
if (!session.user.accessToken) {
response.speechText = "Hi there, to experience the best of our service, request you to link your account. please click on, Link Account in your alexa app";
response.isAccountLinking = "true";
response.shouldEndSession = true;
response.done();
} else {
var conn = new jsforce.Connection({
instanceUrl: process.env.INSTANCE_URL,
accessToken: session.user.accessToken
});
conn.identity(function (err, res) {
session.attributes.loggedInUser = res;
if (err) { return console.error(err); }
console.log("user ID: " + res.user_id);
console.log("organization ID: " + res.organization_id);
console.log("username: " + res.username);
console.log("display name: " + res.display_name);
response.speechText = `Hi ${res.display_name}, How can I help you today?`;
response.repromptText = 'How can I help you today?';
response.shouldEndSession = false;
response.done();
});
}
}
这是工作良好,并给出准确的结果,如预期的。现在我想使用这个已建立的会话变量并传递到我的restServices文件,这样,我就不会进行不必要的调用
我这样做的方式是在conn.identity
block之前,我将会话变量作为
session.attributes.conn=conn
我得到的错误是
{“errorType”:“Error”,“errorMessage”:“无法字符串化”
响应正文“,”堆栈“:[”错误:无法字符串化
响应主体“,”at\U trySerializeResponse
(/var/runtime/RAPIDClient.js:166:11)“,”在
RAPIDClient._post(/var/runtime/RAPIDClient.js:127:22)”,“在RAPIDClient.postInvocationResponse (/var/runtime/RAPIDClient.js:39:10)“,”完成时 (/var/runtime/CallbackContext.js:34:12)“,”完成时 (/var/runtime/CallbackContext.js:59:7)“,”成功 (/var/runtime/CallbackContext.js:63:5)“,”位于Object.success (/var/runtime/CallbackContext.js:105:16)“,”位于 Response.done(/var/task/index.js:79:23)“,”位于 /var/task/index.js:200:22 /var/task/node_modules/jsforce/lib/promise.js:72:9“]} 考虑到stringify的一些问题,将此行更改为 session.attributes.conn=JSON.stringify(conn) 现在,我得到下面的错误 {“errorType”:“TypeError”,“errorMessage”:“转换循环” 结构转换为JSON,“堆栈”:[“TypeError:正在转换 JSON.stringify处的JSON“”的循环结构 (),“at/var/task/index.js:198:44,”
at/var/task/node_modules/jsforce/lib/promise.js:72:9“,”at 进程。_tickCallback(internal/process/next_tick.js:61:11)“]} 这是非常令人困惑的,无法理解我错在哪里。请告诉我如何修理它 我还想知道如何将此conn发送到我的restServices文件 谢谢