Q&A

lineClient.pushMessage not working

Pre condition, Condition to reproduce

I am using @line-bot/sdk to implement line bot with third part application. Able send the message from Line to my third party application using below method app.post('/event', line.middleware(configuration), function(req, res){ } The message I got from third party application I am try to send back to Line push message using below request:

app.post('/new-message', bodyParser.json(), function(request, response) { // console.log(request)

    clients.map((l_client, index) => {
        if(l_client['flex_channel'] == request.query.channel) {
            console.log('Message receveid from Twilio webhook fired',request.body.Body);
            let message = new TextMessage(request.body.Body);
            //let message = new PictureMessage(request.body.Body);
            //l_client['user_bot'].send(message);
            lineClient.pushMessage(l_client['LineID'], {
                type: 'text',
                text: message,
              }).then(res=>{
                  console.log(res)
              }).catch(error=>{
                  console.log(error)
              })
            
        }
    });

});

Issue/ Error Message details

Message receveid from Twilio webhook fired Hello HTTPError: Request failed with status code 400 at HTTPClient.wrapError (E:\Project\Line-bot-develop\node_modules@line\bot-sdk\dist\http.js:89:20) at E:\Project\Line-bot-develop\node_modules@line\bot-sdk\dist\http.js:19:88 at processTicksAndRejections (internal/process/task_queues.js:93:5) at async HTTPClient.post (E:\Project\Line-bot-develop\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 (E:\Project\Line-bot-develop\node_modules\axios\lib\core\createError.js:16:15) at settle (E:\Project\Line-bot-develop\node_modules\axios\lib\core\settle.js:17:12) at IncomingMessage.handleStreamEnd (E:\Project\Line-bot-develop\node_modules\axios\lib\adapters\http.js:260:11) at IncomingMessage.emit (events.js:327:22) at endReadableNT (internal/streams/readable.js:1327:12) at processTicksAndRejections (internal/process/task_queues.js:80:21) { config: { url: 'https://api.line.me/v2/bot/message/push', method: 'post', data: '{"messages":[{"type":"text","text":{"text":"Hello","trackingData":{},"keyboard":null,"requiredArguments":["text"]}}],"to":"UserID","notificationDisabled":false}', headers: [Object], transformRequest: [Array], transformResponse: [Array], timeout: 0, adapter: [Function: httpAdapter], xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, validateStatus: [Function: validateStatus] }, request: ClientRequest { _events: [Object: null prototype], _eventsCount: 7, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: true, chunkedEncoding: false, shouldKeepAlive: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: true, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, _contentLength: null, _hasBody: true, _trailer: '', finished: true, _headerSent: true, socket: [TLSSocket], _header: 'POST /v2/bot/message/push HTTP/1.1\r\n' + 'Accept: application/json, text/plain, /\r\n' + 'Content-Type: application/json;charset=utf-8\r\n' + 'Authorization: Bearer Removed to restrict public view' + 'User-Agent: @line/bot-sdk/7.3.0\r\n' + 'Content-Length: 187\r\n' + 'Host: api.line.me\r\n' + 'Connection: close\r\n' + '\r\n', _keepAliveTimeout: 0, _onPendingData: [Function: noopPendingOutput], agent: [Agent], socketPath: undefined, method: 'POST', maxHeaderSize: undefined, insecureHTTPParser: undefined, path: '/v2/bot/message/push', _ended: true, res: [IncomingMessage], aborted: false, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null, reusedSocket: false, host: 'api.line.me', protocol: 'https:', _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: toJSON] } }

Accompanying respective source code

app.post('/new-message', bodyParser.json(), function(request, response) { // console.log(request) if (request.body.Source === 'SDK' ) { // from twillo clients.map((l_client, index) => { if(l_client['flex_channel'] == request.query.channel) { console.log('Message receveid from Twilio webhook fired',request.body.Body); let message = new TextMessage(request.body.Body); //let message = new PictureMessage(request.body.Body); //l_client['user_bot'].send(message); lineClient.pushMessage(l_client['LineID'], { type: 'text', text: message, }).then(res=>{ console.log(res) }).catch(error=>{ console.log(error) })

        }
    });
}

});

Resolution Tried

Reference information (Version / Platform/ environment)

  • 0
  • 1
  • 1154
  • twitter facebook

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