Push LineBot from Rails It is a guy who sends at any time as shown below
There are many articles, so please refer to them. For example, there is the following article
The world's most easy-to-understand explanation of how to make a LINE BOT (1) [Account preparation]
line-bot-api
with Gemfileand ʻENV ["LINE_CHANNEL_TOKEN "]
must be set on the server side such as heroku. I will explain after thislinebot_controller.rb
class LinebotController < ApplicationController
require 'line/bot' # gem 'line-bot-api'
def client
@client ||= Line::Bot::Client.new { |config|
config.channel_secret = ENV["LINE_CHANNEL_SECRET"]
config.channel_token = ENV["LINE_CHANNEL_TOKEN"]
}
end
def push
message={
type: 'text',
text: "hello"
}
user_id = '[User ID of the destination LINE account]'
response = client.push_message(user_id, message)
end
end
There are many articles on deploying Rails apps, please refer to them. For example, there is the following article
Procedure to deploy Rails app on Heroku
At this time, be sure to set channel basic settings-> channel secret, Messaging API settings-> channel access token to heroku as shown below.
$ heroku config:set LINE_CHANNEL_SECRET="[Channel secret]"
$ heroku config:set LINE_CHANNEL_TOKEN="[Channel access token]"
Execute the action push of linebot_controller.rb of Rails application deployed on heroku I was able to push "hello" as shown below
Recommended Posts