[Bitcoin] 거래 ID를 보낼 때 확인 수를 반환하는 LINE BOT
개요
 
사용자가 보낸 트랜잭션 ID를 기반으로 bitFlyer chainFlyer API
 코드
callback.rbrequire 'sinatra'
require 'line/bot'
require 'json'
require 'open-uri'
def client
  @client ||= Line::Bot::Client.new { |config|
    config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
    config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
  }
end
post '/callback' do
  body = request.body.read
  signature = request.env['HTTP_X_LINE_SIGNATURE']
  unless client.validate_signature(body, signature)
    error 400 do 'Bad Request' end
  end
  events = client.parse_events_from(body)
  events.each { |event|
    case event
    when Line::Bot::Event::Message
      case event.type
      when Line::Bot::Event::MessageType::Text
        begin
          #ユーザーから送られてきたメッセージ
          events_message_text = JSON.parse(body)["events"][0]["message"]["text"]
          #送られてきたメッセージ=トランザクションIDをエンドポイントURLに結合し、トランザクションの情報を取得
          transaction_info = open("https://chainflyer.bitflyer.jp/v1/tx/"+events_message_text).read
          #確認数
          confirmed = JSON.parse(transaction_info)["confirmed"]
          message = {type:'text',text:confirmed}
        rescue
          #送られてきたメッセージがトランザクションIDでではない場合の処理
          message = {type:'text',text:"トランザクションが見つかりません"}
        end
        client.reply_message(event['replyToken'], message)
      end
    end
  }
  "OK"
end
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여([Bitcoin] 거래 ID를 보낼 때 확인 수를 반환하는 LINE BOT), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/a-r-i/items/75b11840c87cffc53785
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
callback.rb
require 'sinatra'
require 'line/bot'
require 'json'
require 'open-uri'
def client
  @client ||= Line::Bot::Client.new { |config|
    config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
    config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
  }
end
post '/callback' do
  body = request.body.read
  signature = request.env['HTTP_X_LINE_SIGNATURE']
  unless client.validate_signature(body, signature)
    error 400 do 'Bad Request' end
  end
  events = client.parse_events_from(body)
  events.each { |event|
    case event
    when Line::Bot::Event::Message
      case event.type
      when Line::Bot::Event::MessageType::Text
        begin
          #ユーザーから送られてきたメッセージ
          events_message_text = JSON.parse(body)["events"][0]["message"]["text"]
          #送られてきたメッセージ=トランザクションIDをエンドポイントURLに結合し、トランザクションの情報を取得
          transaction_info = open("https://chainflyer.bitflyer.jp/v1/tx/"+events_message_text).read
          #確認数
          confirmed = JSON.parse(transaction_info)["confirmed"]
          message = {type:'text',text:confirmed}
        rescue
          #送られてきたメッセージがトランザクションIDでではない場合の処理
          message = {type:'text',text:"トランザクションが見つかりません"}
        end
        client.reply_message(event['replyToken'], message)
      end
    end
  }
  "OK"
end
Reference
이 문제에 관하여([Bitcoin] 거래 ID를 보낼 때 확인 수를 반환하는 LINE BOT), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/a-r-i/items/75b11840c87cffc53785텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)