Last active
September 6, 2018 10:49
-
-
Save noriyukitakei/716d66abd02664360aa075cb6e4136dc to your computer and use it in GitHub Desktop.
【多分わかりやすいサーバーレスアーキテクチャ入門 〜 「Azure Functions」を使って、クラウドネイティブなLINE風チャットアプリを作ろう!! 〜 】addMessage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (context, req) { | |
// Yahoo!から送られてくるIDに対応した名前を決めておく。チャットの画面に表示される。 | |
const NAMES = { | |
LBHNLYCPWDV3UTO5HVVBFIXTMA:'たけい' | |
} | |
// API Managementから送られてくるYahoo!のIDをリクエストヘッダから取得します。 | |
var uid = req.headers['x-yahoo-uid']; | |
var json = req.body; | |
// もともとクライアントから送られてきたJSONに名前のフィールドを挿入して、Cosmos DBに保存します。 | |
var message = { | |
uid: uid, | |
name: NAMES[uid], | |
message: json.message, | |
pubDate: json.pubDate | |
} | |
context.bindings.outputDocument = message; | |
context.res = { | |
// status: 200, /* Defaults to 200 */ | |
status: 200, | |
}; | |
context.done(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment