Azure functionsをLINEのボットサーバーとして利用しようと考えています。
ユーザが送ったメッセージをCosmosDBに保存したいのですが、どのように記述していいのか、参考になる記事がなかなか出てきません。
botが何か質問を投げて、ユーザーがAとかBを回答すればその結果とユーザー情報を取得し、DBに保存できるというのが目標です。
有識者のかたご回答をお願いいたします。
現在の状況は
LINEディベロッパーアカウント:作成済み
Azure Functionの関数:作成済み
オウム返しのボットは作成し、動くのは確認。(以下にコード記載)
javaScript
1const line = require('@line/bot-sdk'); 2 3const config = { 4 channelAccessToken: 'XXXX', 5 channelSecret: 'XXXXX', 6}; 7 8const client = new line.Client(config); 9 10module.exports = async function (context, req) { 11 context.log('JavaScript HTTP trigger function processed a request.'); 12 13 if (req.query.message || (req.body && req.body.events)) { 14 if (req.body && req.body.events[0]) { 15 message = { 16 type: "text", 17 text: req.body.events[0].message.text 18 } 19 console.log(message); 20 if (req.body.events[0].replyToken) { 21 client.replyMessage(req.body.events[0].replyToken, message); 22 } 23 } 24 else { 25 context.res = { 26 status: 200, 27 body: req.query.message 28 }; 29 } 30 } 31 else { 32 context.res = { 33 status: 200, 34 body: "Please check the query string in the request body" 35 }; 36 }; 37};
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/14 00:14