ほとんどのnode.jsボットフレームワークの例には、会話を構造化するのに最適なウォーターフォールダイアログモデルの概念がありますが、私たち自身のチャットシステムがあるので、これは必要ありません。 WebHook経由でメッセージを受信し、処理し、ダイアログシステムなしで応答します。非同期ボットフレームワーク対応可能ですか?
また、そして今、私たちは問題の核心になっている;)、私が見てきた例では、Webコンテキストでbotframeworkに戻って通信する:
var connector = new builder.ChatConnector({config});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
bot.dialog('/', (session, args) => {
session.sendTyping();
session.send('Echo'+ session.message.text);
})
上記の例は単純で応答します "エコー 'とそのセットの前に入力状態です。 システムは非同期で動作しますが、現在作業しているのはコネクタのリッスンとダイアログのスキームをバイパスすることです。ボットフレームメッセージをキューに入れる方法の簡単な例。キュー処理で
server.post('/api/messages/:name', (req, res, next)=>{
queue.post('botframework',req.params.name,req.body)
.then(()=>res.sendStatus(200))
});
、我々はbotframeworkオブジェクトを構築:
//the ':name' from the snippet above is used to identify
//the bot a retrieve credentials
const connector = new botbuilder.ChatConnector({
appId: bot.properties.botframework_id.value.appId,
appPassword: bot.properties.botframework_id.value.appPassword
});
const username=message.from.name.replace(/[\s-;:"';$]/g,"_")+"_skype";
var address = {
"channelId": message.channelId,
"user": message.from,
"bot": message.recipient,
"serviceUrl": message.serviceUrl,
"useAuth": true
};
let bot = new botbuilder.UniversalBot(connector);
let msg = new botbuilder.Message();
//processing...
//create the outgoing message...
bot.send(msg);
ここで、私たちにとっての問題は、我々は単に生のウェブフックメッセージからセッションオブジェクトを作成する方法を知らないということです多くのメッセージが素早く連続して送信されるときに、タイピングインジケータとメッセージの順序を保証するために必要です。ここで
は、私たちが達成したいものです。
//the ':name' from the snippet above is used to identify
//the bot a retrieve credentials
//the context is non HHTP
const connector = new botbuilder.ChatConnector({
appId: bot.properties.botframework_id.value.appId,
appPassword: bot.properties.botframework_id.value.appPassword
});
const username=message.from.name.replace(/[\s-;:"';$]/g,"_")+"_skype";
var address = {
"channelId": message.channelId,
"user": message.from,
"bot": message.recipient,
"serviceUrl": message.serviceUrl,
"useAuth": true
};
let bot = new botbuilder.UniversalBot(connector);
let session = bot.createSession();
session.sendTyping();
let message = getNextMessageFromChatServer(message);
session.send(message);
//more messages to be send?
//....
そこで質問:どのように我々は、生データからセッションオブジェクトを作成することができbotframeworkのウェブフックに送信しますか?
を使用してセッションを構築することができるはずです。それは 'bot.loadSession(アドレス、(エラー、セッション)=> {'。あなたがあなたの答えを変更する場合、私は正解として受け入れる!) –
@StanWiechers完了! – bilby91