Giter Site home page Giter Site logo

studio3104 / line-bot-sdk-ruby Goto Github PK

View Code? Open in Web Editor NEW

This project forked from line/line-bot-sdk-ruby

0.0 2.0 0.0 57 KB

SDK of the LINE BOT API Trial for Ruby

Home Page: https://developers.line.me/

License: Apache License 2.0

Ruby 100.00%

line-bot-sdk-ruby's Introduction

Line::Bot::API

Line::Bot::API - SDK of the LINE BOT API Trial for Ruby

Gem-version Build Status

Installation

Add this line to your application's Gemfile:

gem 'line-bot-api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install line-bot-api

Configuration

client = Line::Bot::Client.new do |config|
  config.channel_id = 'YOUR LINE BOT Channel ID'
  config.channel_secret = 'YOUR LINE BOT Channel Secret'
  config.channel_mid = 'YOUR LINE BOT MID'
end

Usage

Sending messages

After configuring a client, you can start sending messages as the following reference.

Sending message APIs requires the following parameter.

  • :to_mid String or Array
client.send_text(
  to_mid: '12345678',
)
client.send_text(
  to_mid: ['12345678', '23456789'],
)

send_text

client.send_text(
  to_mid: to_mid,
  text: 'Hello',
)

send_image

client.send_image(
  to_mid: to_mid,
  image_url: 'http://example.com/image.jpg',            # originalContentUrl
  preview_url: 'http://example.com/image_preview.jpg',  # previewImageUrl
)

send_video

client.send_video(
  to_mid: to_mid,
  video_url: 'http://example.com/video.mp4',            # originalContentUrl
  preview_url: 'http://example.com/video_preview.jpg'   # previewImageUrl
)

send_audio

client.send_audio(
  to_mid: to_mid,
  audio_url: 'http://example.com/audio.mp3',            # originalContentUrl
  duration: 120000
)

send_location

client.send_location(
  to_mid: to_mid,
  title: 'LINE Corporation.',
  address: 'Hikarie  Shibuya-ku Tokyo 151-0002',        # location.address
  latitude: 35.61823286112982,                          # location.latitude
  longitude: 139.72824096679688,                        # location.longitude
)

send_sticker

See online documentation to find which sticker's you can send.

client.send_sticker(
  to_mid: to_mid,
  stkpkgid: 2,                                          # contentMetadata.STKPKGID
  stkid: 144,                                           # contentMetadata.STKID
  stkver: 100                                           # contentMetadata.STKVER
)

Sending multiple message

Support on sending multiple message.

client.multiple_message.add_text(
  text: text,
).add_image(
  image_url: image_url,
  preview_url: preview_url,
).add_video(
  video_url: video_url,
  preview_url: preview_url,
).add_audio(
  audio_url: audio_url,
  duration: duration,
).add_location(
  title: 'title',
  latitude: latitude,
  longitude: longitude,
).add_sticker(
  stkpkgid: stkpkgid,
  stkid: stkid,
  stkver: stkver,
).send(
  to_mid: to_mid,
)

Sending rich message

Support on sending rich message.

See also a online document.

client.rich_message.set_action(
  MANGA: {
    text: 'manga',
    link_url: link_url,
  }
).add_listener(
  action: 'MANGA',
  x: 0,
  y: 0,
  width: 520,
  height: 520,
).send(
  to_mid: to_mid,
  image_url: image_url,
  alt_text: alt_text,
)

Signature validation

request = Rack::Request.new( .. )
signature = request.env['HTTP_X_LINE_CHANNELSIGNATURE']
unless client.validate_signature(request.body.read, signature)
  return 'invalidation of signature'
end

Receiving request

request_from_rack = Rack::Request.new( .. )

request = Line::Bot::Receive::Request.new(request_from_rack.env)
request.data #=> [Array<Line::Bot::Receive::Message || Line::Bot::Receive::Operation>]

request.data.each { |message|
  case message.content
  when Line::Bot::Message::Image, Line::Bot::Message::Video
    # get message content
    response = client.get_message_content(message.id)
    tf = Tempfile.open("content")
    tf.write(response.body)

    # get preview of message content
    preview_response = client.get_message_content_preview(message.id)
    ptf = Tempfile.open("content_preview")
    ptf.write(preview_response.body)
  end
}

Getting message content

Get the original file which was sent by user.

Getting preview of message content

Get the preview image file which was sent by user.

Getting user profile information

user_profile = client.get_user_profile("1234567")
user_profile #=> [Line::Bot::Response::User::Profile]
user_profile.contacts #=> [Array<Line::Bot::Response::User::Contact>]

License

The gem is available as open source under the terms of the Apache License, Version 2.0.

Links

line-bot-sdk-ruby's People

Contributors

hirohisa avatar kimoto avatar

Watchers

Satoshi SUZUKI avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.