當使用者傳sticker時會出現以下error:
message:
{ mid: '72bwF7hUgkhXPoyjkG9KZ9ZaWfqYUnYbmnxSzW6lk5oJXbGrO0f07ALLiy67ExQEEhQYOCQzKtAB-aXRo24F_Q',
attachments: [ [Object] ],
sticker_id: 608766616236239 } }
Sender PSID: 2...
TypeError: console.logs is not a function
at handleMessage (/app/app.js:175:19)
at /app/app.js:54:9
at Array.forEach (<anonymous>)
at app.post (/app/app.js:40:16)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at next (/app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/app/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
at /app/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
app.js
if (messageAttachments) {
var json = JSON.parse(JSON.stringify(messageAttachments));
var attachmentType = json[0]['type'];
switch (attachmentType) {
case 'audio':
console.log('請稍後,我們已經收到語音檔案附件,馬上為你進行辨識');
// response = {
// "text": `請稍後,我們已經收到語音檔案附件,馬上為你進行辨識`
// }
// callSendAPI(sender_psid, response);
receivedAudioAttachment(sender_psid, json[0]['payload']['url']);
break;
case 'image':
console.logs('sticker');
default:
console.logs('messenger type:'+attachmentType);
response = {
"text": `收到附件`
}
callSendAPI(sender_psid, response);
}
}
但是他卻顯示不出attachmentType,然後就一直卡住。
有什麼辦法可以讓他至少無視不要卡著嗎?
TypeError: console.logs is not a function
要 handler error
可以用 try ... catch
然後你的 switch ... case
少了 break