晴れ時々、FX

My dairy fx life

(9)NGROKのリフレッシュ

ついに完成しました。

NGROKのリフレッシュと、WEBHOOKのリダイレクト

この2本を作るために、いったいどれだけの時間がかかったことか・・・

その中で、いくつかつまずいた点があったので、簡単にメモしておく

結局のところ、doPost(e)で受審したメッセージを、

そのまま、リダイレクトするのに、

JSONオブジェクトをこねくり回すのがポイントだった。

リストを見てもらえば、分かると思うが、

入れ子JSONというのは、かなり深い構造になっている。

JSONに始まり、JSONに終わる。

今回はJSONというものが、いったい何であるのか?

それを全くわかっていなかった自分と

どれだけ向かい合えたのか?

それが課題である。

あとWEBのPOSTメッセージというものの、

基本的な構造など、WEBアプリケーションに必要な

かなりの知識を得ることができた。

あとの課題

NGROKが適当な時間でEXPIREされる。

これを適宜ウォッチングして、もしEXPIREなら

再起動して、リフレッシュを行う

これを完成させれば、もうすべてのプログラムが完成したことになる。

というわけで、来週からCSVデータをがっちり集めていくぞ!!

-----------------------------

function doPost(e){

var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/12pSM7h3C4vmCp9u22lAZLe8rRfYOINNMZMjXWCA9CxI/edit#gid=0");

var param = e.postData.getDataAsString();

var js = JSON.parse(param);

var sheet = ss.getSheets()[0];

var lastRow = sheet.getLastRow();

var url = sheet.getRange(lastRow, 2).getValue();

var sheet = ss.getSheets()[1];

var data = {

"webhook_setting_id": js.webhook_setting_id,

"webhook_event_type": js.webhook_event_type,

"webhook_event_time": js.webhook_event_time,

"webhook_event":{

"from_account_id": js.webhook_event.from_account_id,

"to_account_id": js.webhook_event.to_account_id,

"room_id": js.webhook_event.room_id,

"message_id": js.webhook_event.message_id,

"body": js.webhook_event.body,

"send_time": js.webhook_event.send_time,

"update_time": js.webhook_event.update_time

}

}

var options = {

'method': 'post',

'contentType': 'application/json',

'payload': JSON.stringify(data)

}

var response = UrlFetchApp.fetch(url,options);

}

-----------------------