未分類

LINE Botをつくろう

 

 

Line bot
https://www.linebiz.com/jp/service/line-official-account/

 

YouTube Data API
https://developers.google.com/youtube/v3/docs?hl=ja

 

構成

インフラ

  • Terraform
  • GitLab, Code Deploy, オートスケール
  • Blue / Green

DB

Firebase RealtimeDB

外部API

  • YouTube Data API

 

API

  • Laravel

 

スケジュール

16日

  • LINE BOT作成
  • Laravel
  • GitHub → CodePipeline → Code Deploy →  Blue Green

 

17日

  • Laravel + YouTubeAPI

 

18日

  • 調整

 

19日

  • 審査提出

 

 

16日

LINE BOT作成

LINE登録
https://www.linebiz.com/jp/service/line-official-account/

  • Channel type: Messaging API
  • Provider: Create a new provider
    YOUTUBE-DATA
  • Channel name: YouTube Data
  • Channel description: 競合の分析
  • Category: ウェブサービス
  • Subcategory: ウェブサービス(ビジネス)
  • Email address: 任意のもの
  • Privacy policy URL(optional): 空白
  • Terms of use URL(optional): 空白

 

GAS

 

サンプル

// LINE developersのメッセージ送受信設定に記載のアクセストークン
var ACCESS_TOKEN = '<Your Access Token>';

function doPost(e) {
  // WebHookで受信した応答用Token
  var replyToken = JSON.parse(e.postData.contents).events[0].replyToken;
  // ユーザーのメッセージを取得
  var userMessage = JSON.parse(e.postData.contents).events[0].message.text;
  // 応答メッセージ用のAPI URL
  var url = 'https://api.line.me/v2/bot/message/reply';

  UrlFetchApp.fetch(url, {
    'headers': {
      'Content-Type': 'application/json; charset=UTF-8',
      'Authorization': 'Bearer ' + ACCESS_TOKEN,
    },
    'method': 'post',
    'payload': JSON.stringify({
      'replyToken': replyToken,
      'messages': [{
        'type': 'text',
        'text': userMessage + 'ンゴ',
      }],
    }),
    });
  return ContentService.createTextOutput(JSON.stringify({'content': 'post ok'})).setMimeType(ContentService.MimeType.JSON);
}

 

 

 

$ sudo su -

 

日本時間にする

 

$ sudo timedatectl set-timezone Asia/Tokyo

 

# timedatectl

      Local time: Wed 2020-06-17 00:10:56 JST
  Universal time: Tue 2020-06-16 15:10:56 UTC
        RTC time: Tue 2020-06-16 15:10:56
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

 

# sudo yum install wget unzip vim

 

# getenforce
Enforcing

 

# vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled

# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

 

# reboot now

 

# yum install epel-release
# yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

 

# yum install php php-mysql php-mbstring --enablerepo=remi-php7

 

# yum install httpd

 

# systemctl enable httpd
# systemctl start httpd

 

# yum install certbot python-certbot-apache

 

# certbot certonly -d youtube-api.yuulinux.tokyo
Saving debug log to /var/log/letsencrypt/letsencrypt.log

How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Apache Web Server plugin (apache)
2: Spin up a temporary webserver (standalone)
3: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-3] then [enter] (press 'c' to cancel): 1
Plugins selected: Authenticator apache, Installer None
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): yuu3@example.net
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:

 

(Y)es/(N)o: Y
Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for youtube-api.yuulinux.tokyo
Cleaning up challenges


IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/youtube-api.yuulinux.tokyo/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/youtube-api.yuulinux.tokyo/privkey.pem
   Your cert will expire on 2020-09-14. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

 

# mkdir -p /var/www/vhosts/youtube-api.yuulinux.tokyo/httpdocs

 

# vi /var/www/vhosts/youtube-api.yuulinux.tokyo/httpdocs/callback.php

 

 

# vi /etc/httpd/conf.d/youtube-api.yuulinux.tokyo.conf


<VirtualHost *:443>
  ServerName youtube-api.yuulinux.tokyo
  DocumentRoot /var/www/vhosts/youtube-api.yuulinux.tokyo/httpdocs
  SSLEngine on
  SSLCertificateFile /etc/letsencrypt/live/youtube-api.yuulinux.tokyo/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/youtube-api.yuulinux.tokyo/privkey.pem

  <Directory "/var/www/vhosts/youtube-api.yuulinux.tokyo/httpdocs">
    Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName youtube-api.yuulinux.tokyo
  DocumentRoot /var/www/vhosts/youtube-api.yuulinux.tokyo/httpdocs
  <Directory "/var/www/vhosts/youtube-api.yuulinux.tokyo/httpdocs">
    Require all granted
  </Directory>
</VirtualHost>

 

# httpd -t
Syntax OK

 

# systemctl restart httpd

 

composerインストール

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

 

# mv composer.phar /usr/local/bin/composer
# chmod +x /usr/local/bin/composer

 

LINE-SDK

# composer require linecorp/line-bot-sdk

 

 

 

https://youtube-api.yuulinux.tokyo/callback.php

 

 

資料

 

 

 

 

 

 

Amazonおすすめ

iPad 9世代 2021年最新作

iPad 9世代出たから買い替え。安いぞ!🐱 初めてならiPad。Kindleを外で見るならiPad mini。ほとんどの人には通常のiPadをおすすめします><

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)