Skip to content

Instantly share code, notes, and snippets.

@noriyukitakei
Last active September 6, 2018 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noriyukitakei/716d66abd02664360aa075cb6e4136dc to your computer and use it in GitHub Desktop.
Save noriyukitakei/716d66abd02664360aa075cb6e4136dc to your computer and use it in GitHub Desktop.
【多分わかりやすいサーバーレスアーキテクチャ入門 〜 「Azure Functions」を使って、クラウドネイティブなLINE風チャットアプリを作ろう!! 〜 】addMessage
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