@@ -27,12 +27,17 @@ def reply_text(event, texts)
2727 )
2828end
2929
30+ def broadcast ( messages )
31+ client . broadcast ( messages )
32+ end
33+
3034def reply_content ( event , messages )
3135 res = client . reply_message (
3236 event [ 'replyToken' ] ,
3337 messages
3438 )
3539 logger . warn res . read_body unless Net ::HTTPOK === res
40+ res
3641end
3742
3843post '/callback' do
@@ -532,6 +537,31 @@ def handle_message(event)
532537 client . leave_room ( event [ 'source' ] [ 'roomId' ] )
533538 end
534539
540+ when 'stats'
541+ response = broadcast ( {
542+ type : 'template' ,
543+ altText : 'stats' ,
544+ template : {
545+ type : 'buttons' ,
546+ thumbnailImageUrl : THUMBNAIL_URL ,
547+ title : 'stats sample' ,
548+ text : 'Hello, my stats' ,
549+ actions : [
550+ { label : 'Go to line.me' , type : 'uri' , uri : 'https://line.me' , altUri : { desktop : 'https://line.me#desktop' } } ,
551+ { label : 'Send postback' , type : 'postback' , data : 'hello world' } ,
552+ { label : 'Send postback2' , type : 'postback' , data : 'hello world' , text : 'hello world' } ,
553+ { label : 'Send message' , type : 'message' , text : 'This is message' }
554+ ]
555+ }
556+ } )
557+ request_id = response . header [ "X-Line-Request-Id" ]
558+ reply_text ( event , "RequestId: #{ request_id } " )
559+
560+ when /\A stats\s +(?<request_id>.+)/
561+ request_id = Regexp . last_match [ :request_id ]
562+ stats = client . get_user_interaction_statistics ( request_id )
563+ reply_text ( event , "[STATS]\n #{ stats . body } " )
564+
535565 else
536566 reply_text ( event , "[ECHO]\n #{ event . message [ 'text' ] } " )
537567
0 commit comments