私はDirectlineのlibに基づいてMicrosoftボットフレームワーク上のチャットにメッセージを送信し、回答で返信するアプリケーションを構築しようとしています。このアプリケーションは、ボットクライアントにメッセージを転送するPOST要求を送信する必要のあるWebアプリケーションであり、Microsoftのボットフレームワークからのボットの応答で返信します。nodejsクライアントからmicrosoftボットへの会話を開始する方法
HTTP POSTリクエストの例:
http://host:port/api/message をBODY: {メッセージ: "こんにちは"}
それに関連するチャットボットにテキストとして"HI"を送るべきMicrosoft Botのフレームワークとフレームワークがこれまで返答してきたものを返信してください。
私は秘密を入れて、私はそれが動作するようにすべきだったと思うすべてをやったが、私はチャットボットと話すべき会話を生成している問題を抱えている。
これは私がそれをやった方法です:
"use strict";
require('dotenv').config();
var express = require('express');
var app = express();
var fs = require("fs");
var bodyParser = require("body-parser");
var http = require('http');
var postLib = require("./lib");
var messageFilePath="message.out";
var cors = require('cors');
var uuid = require('uuid');
//new botclient
var client = require('directline-api');
// config items
var pollInterval = 1000;
var directLineSecret = 'secret';
var directLineClientName = 'DirectLineClient';
var directLineSpecUrl = 'https://docs.botframework.com/en-us/restapi/directline3/swagger.json';
///bot client end
var sendmail = require('sendmail')({silent: true})
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
app.options('*', cors()); // include before other routes
var corsOptions = {
origin: '*',
optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204
};
app.post('/interact/message', cors(corsOptions), function(req, res) {
var uuid1 = uuid.v1();
var bodyMessage = JSON.stringify(req.body);
var log = uuid1 + ', ' + new Date().getTime() + ", " + bodyMessage;
if (req.query.botId == 1) {
emailMessage(log);
res.send(postLib.reply.reply);
}
if (req.query.botId == 2) {
botMessage(bodyMessage.message);
res.send(postLib.reply.reply);
}
});
function emailMessage(log){
sendmail({
from: postLib.mail.from,
to: postLib.mail.to,
subject: postLib.mail.subject,
html: 'this is the log: [' + log + ']',
}, function(err, reply) {
console.log(err && err.stack);
console.dir(reply);
});
fs.appendFile(messageFilePath, "\n" + log, function(error){
if (error) throw error;
});
}
function botMessage(message){
var token = client.getToken(directLineSecret);
// create a conversation
var conversationId = client.createConversation(token);
// post a message in a conversation
client.postMessage(token, conversationId, {
text: message
});
return client.getMessage(token, conversationId, 0);
}
var server = app.listen(8082, function() {
var host = server.address().address
var port = server.address().port
console.log("interact post server listening at http://%s:%s", host, port)
})
私はすでにそれをチェックして、私が欲しいものを解決することはできませんでした。私が説明しようとしましょう。私はhttpクライアントからjsonのような本文のテキスト付き投稿リクエストを送信できるようにしたいので、ボットクライアントを介してメッセージを渡し、ボットの返信で応答する必要があります。 – user4860092
しかし、DirectLineを使用していますか?またはボットと会話するREST API?あなたはあなたの問題を説明していません –
簡単な会話をサポートするために私自身の残りのAPIサービスを公開したいので、単純な標準のPOSTリクエストを送信すると、そのメッセージがボットクライアントに渡されます。ボットクライアントは、Microsoftのフレームワークボットと、ダイレクトラインAPIを使って話し合う必要があります。それは親切な会話のレイヤーです。私が構築しようとしているより単純なレイヤーです。 – user4860092