1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LINEAPIとGASを使って遊んでみた2

Last updated at Posted at 2018-08-14

Weblio中国語検索君

説明

Weblio中国語を使用したLINEBotです。

使い方

1:LINEで文字を入力して送信します。
2:LINEに入力したキーワードを、Weblio中国語で検索した結果が返ってきます。

コード

中国語辞書君.gs
var PROPERTIES = PropertiesService.getScriptProperties();

var LINE_ACCESS_TOKEN = PROPERTIES.getProperty('LINE_ACCESS_TOKEN')
var LINE_END_POINT = "https://api.line.me/v2/bot/message/reply"
var reply_token;
var query;

function doPost(e){
if (typeof e === "undefined"){
 reply_token = ""
 query = "本"
} else{
    var json = JSON.parse(e.postData.contents);
    reply_token= json.events[0].replyToken;
    //送られたLINEメッセージを取得
    query = json.events[0].message.text;
  }
  Logger.log("検索キーワード"+query);
 postBookToLine(query);
}

function postBookToLine(query){
var messages = [{
 "type": "text",
 "text": "https://cjjc.weblio.jp/content/" + query
}];
Logger.log(messages)
UrlFetchApp.fetch(LINE_END_POINT, {
 'headers': {
   'Content-Type': 'application/json; charset=UTF-8',
   'Authorization': 'Bearer ' + LINE_ACCESS_TOKEN,
 },
 'method': 'post',
 'payload': JSON.stringify({
   'replyToken': reply_token,
   'messages': messages,
 }),
});   
}
1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?