iT邦幫忙

2

關於FB messenger處理sticker的問題

當使用者傳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,然後就一直卡住。
有什麼辦法可以讓他至少無視不要卡著嗎?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

6
dragonH
iT邦超人 5 級 ‧ 2019-09-17 09:10:41
最佳解答
TypeError: console.logs is not a function

/images/emoticon/emoticon19.gif

要 handler error

可以用 try ... catch

然後你的 switch ... case

少了 break

看更多先前的回應...收起先前的回應...
froce iT邦大師 1 級 ‧ 2019-09-17 10:46:31 檢舉

這年頭debug都丟給網友,自己都不用看的。XD

dragonH iT邦超人 5 級 ‧ 2019-09-17 10:54:38 檢舉

/images/emoticon/emoticon39.gif

小魚 iT邦大師 1 級 ‧ 2019-09-17 12:06:15 檢舉

自己努力了多少,
就會得到多少,
這也沒什麼.

Huiicat iT邦新手 4 級 ‧ 2019-09-17 12:16:09 檢舉

感謝各位指教!
因為每次修改都需要上傳到heroku,而他的logs error出現太慢,導致要等很久才知道狀況,就想來請問各位。
我會再試試看,謝謝~

dragonH iT邦超人 5 級 ‧ 2019-09-17 12:49:34 檢舉

Huiicat

如果你是因為 webhook 的問題的話

可以試試 ngrok

開發會更有效率

我要發表回答

立即登入回答