client.replyMessage Bad Request 400

I am trying create a chat bot using @line/bot-sdk. While sending reply i am getting 400 bad request. Below is the Error Log Error Message HTTPError: Request failed with status code 400 at HTTPClient.wrapError (/var/task/node_modules/@line/bot-sdk/dist/http.js:88:20) at /var/task/node_modules/@line/bot-sdk/dist/http.js:19:88 at processTicksAndRejections (internal/process/task_queues.js:97:5) at async HTTPClient.post (/var/task/node_modules/@line/bot-sdk/dist/http.js:33:21) { statusCode: 400, statusMessage: 'Bad Request', originalError: Error: Request failed with status code 400 at createError (/var/task/node_modules/axios/lib/core/createError.js:16:15) at settle (/var/task/node_modules/axios/lib/core/settle.js:17:12) at IncomingMessage.handleStreamEnd (/var/task/node_modules/axios/lib/adapters/http.js:236:11) at IncomingMessage.emit (events.js:322:22) at endReadableNT (_stream_readable.js:1187:12) at processTicksAndRejections (internal/process/task_queues.js:84:21) { config: { url: 'https://api.line.me/v2/bot/message/reply', method: 'post', data: '{"messages":[{"type":"text","text":"Thanks for using our services."}],"replyToken":"8f0786141f64435bab0157fe49653a33","notificationDisabled":false}', headers: [Object], transformRequest: [Array], transformResponse: [Array], timeout: 0, adapter: [Function: httpAdapter], xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, validateStatus: [Function: validateStatus] }, request: ClientRequest { _events: [Object: null prototype], _eventsCount: 6, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, _last: true, chunkedEncoding: false, shouldKeepAlive: false, useChunkedEncodingByDefault: true, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [TLSSocket], connection: [TLSSocket], _header: 'POST /v2/bot/message/reply HTTP/1.1\r\n' + 'Accept: application/json, text/plain, /\r\n' + 'Content-Type: application/json\r\n' + 'Authorization: Bearer {my access token}' + 'User-Agent: @line/bot-sdk/7.0.0\r\n' + 'Content-Length: 147\r\n' + 'Host: api.line.me\r\n' + 'Connection: close\r\n' + '\r\n', _onPendingData: [Function: noopPendingOutput], agent: [Agent], socketPath: undefined, method: 'POST', insecureHTTPParser: undefined, path: '/v2/bot/message/reply', _ended: true, res: [IncomingMessage], aborted: false, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null, reusedSocket: false, _redirectable: [Writable], [Symbol(kCapture)]: false, [Symbol(kNeedDrain)]: false, [Symbol(corked)]: 0, [Symbol(kOutHeaders)]: [Object: null prototype] }, response: { status: 400, statusText: 'Bad Request', headers: [Object], config: [Object], request: [ClientRequest], data: [Object] }, isAxiosError: true, toJSON: [Function] } }

Please look at this log and let me know where I am doing wrong?

I am also adding my code below

'use strict'; //const serverless = require('serverless-http'); const line = require('@line/bot-sdk'); const express = require('express'); const util = require('util'); const config = { channelAccessToken: 'my access token', channelSecret: 'my client secret' }; const client = new line.Client(config);

exports.handler = (line.middleware(config), (req, res, callback) => { //const readFile = util.promisify(line.middleware(config)); //await readFile; const events = req.events; Promise.all(events.map((event) => { return handleEvent(event).catch((error) => { console.log("Erorororo ",error);return null; }); })) .then((result) => { console.log("result log", result); callback(null, { statusCode: 200, body: {} }); }); }); async function handleEvent(event) { if (event.type !== 'message' || event.message.type !== 'text') { return Promise.resolve(null); } //console.log(event.message.text); var echo = {}; if(event.message.text.toUpperCase() == "HELLO") { echo = { type: 'text', text: 'Hello World!!!' }; } else { echo = { type: 'text', text: 'Thanks for using our services.' }; } // use reply API return client.replyMessage(event.replyToken, echo); }

  • 0
  • 2
  • 325
  • twitter facebook

It is not recommended to expose your access token in this site...

  • 0

I think the rsponse body (i.e error.response.data) might contain an error description, and it should help you.

  • 0
本当によろしいですか? question.vm