line/line-bot-sdk-ruby

Invalid reply token

ruvaleev opened this issue · 3 comments

System Informations

  • Ruby version: ruby 2.6.5p114 (2019-10-01 revision 67812)
  • Gem (line-bot-api) version: line-bot-api (1.14.1)
  • OS: MacOS Catalina 10.15.6 (19G2021)

Expected Behavior

I run response = client.reply_message(reply_token, message)
and got
{}
and can see new message in channel.

Current Behavior

Im trying to send reply_message, as were described in docs. But every time I got the same error:

response = client.reply_message(reply_token, message)
=> #<Net::HTTPBadRequest 400 Bad Request readbody=true>

response.body
=> "{\"message\":\"Invalid reply token\"}"

But reply token I got from logs in my server:

BODY
{"events":[{"type":"message","replyToken":"c39a30ae43c042b691808ef9a94ca71d","source":{"userId":"Ue90e91bcbdfab7ec1ef9721a007d3e9a","type":"user"},"timestamp":1599901194313,"mode":"active","message":{"type":"text","id":"12666060016961","text":"Why? "}}],"destination":"Ufb9df14b31bd446d8ffb1e4e979a41f2"}

I've tried to do same request in Postman with raw json body, and only one time it was successful. I've tried different reply tokens (I send message to channel, look at logs and copy new reply token, like 'c39a30ae43c042b691808ef9a94ca71d' in this case). But only one time in Postman it was successfull, and dozen other times from ruby console and from postman as well was ended with same error.

What can be reason of such a strange behaviour?

Steps to Reproduce

I use sinatra on Heroku and logging requests with this way:

post '/callback' do
      body = request.body.read
      logger.warn('BODY')
      logger.warn(body)
      ...

after that look at logs

BODY
{"events":[{"type":"message","replyToken":"c39a30ae43c042b691808ef9a94ca71d","source":{"userId":"Ue90e91bcbdfab7ec1ef9721a007d3e9a","type":"user"},"timestamp":1599901194313,"mode":"active","message":{"type":"text","id":"12666060016961","text":"Why? "}}],"destination":"Ufb9df14b31bd446d8ffb1e4e979a41f2"}

copy 'c39a30ae43c042b691808ef9a94ca71d' to reply_token variable
and copy example message from docs:

reply_token = 'c39a30ae43c042b691808ef9a94ca71d'
message = {
  type: 'text',
  text: 'hello'
}


client = Line::Bot::Client.new { |config|
    config.channel_secret = "<channel secret>"
    config.channel_token = "<channel access token>"
}
response = client.reply_message(reply_token, message)
p response.body
"{\"message\":\"Invalid reply token\"}"

Logs

described above

I don't know about your environment details, but there're some expected situations.

Because the reply token becomes invalid after a certain period of time, responses should be sent as soon as a message is received. Reply tokens can only be used once.

And it may be a question about the API, not SDK. At this time, I'll close this issue.

I tried to send message line from my laravel app but i got every time
{"message":"Invalid reply token"}
this error kindly help to resolve

@gracy282 I need more information.
Is laravel a PHP framework? This repository is for the Ruby language.
So, Please ask the PHP Bot SDK repository, and please describe the situation in more detail.

Example:

  • Sample code that generates the fewest errors possible
  • Request/Response log
  • PHP version
  • SDK version

https://github.com/line/line-bot-sdk-php/issues