2016-04-16 6 views
2

Microsoft Botframeworkの私のPython webapp内で、をREST API callから/bot/v1.0/messagesにしたいと思います。 "ConvId"は、元のメッセージに私の地元のエミュレータによって与えられたIDですBotFrameworkのREST API経由でメッセージに返信するための最小の例は?

{ 
    "text": "Hello, Hello!", 
    "from": { 
    "address": "MyBot" 
    }, 
    "channelConversationId": "ConvId" 
} 

(:

私のローカルマシン上でエミュレータを試して、私はREST呼び出し時の最小ペイロードが何かに似ていることに気づきました注:channelConversationIdconversationIdではありません。

明らかに、これはライブのボットコネクタサイトでは不十分です。しかし、REST APIコール/bot/v1.0/messagesでメッセージに返信する(最小)例は何ですか?

私は、ドキュメントに示されているように属性fromtochannelConversationIdtextlanguageと例えば、異なるペイロードデータをテストしてみました。しかし、通常、私は500エラーを取得する:

{ 
    "error": { 
    "code": "ServiceError", 
    "message": "*Sorry, Web Chat is having a problem responding right now.*", 
    "statusCode": 500 
    } 
} 

答えて

3

最小ペイロードのため:私はちょうどスワップtofromで、元のメッセージを返送しようとしたとき、私は別の500エラーを得た

{ 
    "error": { 
    "message": "Expression evaluation failed. Object reference not set to an instance of an object.", 
    "code": "ServiceError" 
    } 
} 

インラインリプライ(応答として返されます)は次のとおりです。

{ "text": "Hello, Hello!" } 

あなたがout of band usiへの返信を投稿している場合あなたが正しいと思ったら、少しだけもっと必要となるPOSTを/bot/v1.0/messagesにしてください。ここで私はボットビルダーSDKのノードバージョンで何をすべきかです:あなたが戻って元にそれを得るために必要なルーティングビットのすべてを含める必要があるため、既存の会話に返信を送る

// Post an additional reply 
reply.from = ses.message.to; 
reply.to = ses.message.replyTo ? ses.message.replyTo : ses.message.from; 
reply.replyToMessageId = ses.message.id; 
reply.conversationId = ses.message.conversationId; 
reply.channelConversationId = ses.message.channelConversationId; 
reply.channelMessageId = ses.message.channelMessageId; 
reply.participants = ses.message.participants; 
reply.totalParticipants = ses.message.totalParticipants; 
this.emit('reply', reply); 
post(this.options, '/bot/v1.0/messages', reply, (err) => { 
    if (err) { 
     this.emit('error', err); 
    } 
}); 

は少し複雑です会話。新しい会話を開始すると、非常に容易である:

// Start a new conversation 
reply.from = ses.message.from; 
reply.to = ses.message.to; 
this.emit('send', reply); 
post(this.options, '/bot/v1.0/messages', reply, (err) => { 
    if (err) { 
     this.emit('error', err); 
    } 
}); 

どちらの例もreply.text &​​が既に設定されていることを前提としています。

+0

ありがとうSteven! 'reply.to'と' reply.from'の中には何が入っていますか? 4つのサブプロパティがすべて必要ですか( 'channelId'、' address'、 'name'と' id')?おそらく、あなたは 'reply'のJSON表現を追加することができます。再度、感謝します! – Stephan

+0

もう一度おねがいします。Stevenは、一方で、答えはGitHubに追加情報とともに掲載されました。こうして私は新しい答えを書いた。 – Stephan

2

一方、答えは特にwiltodelta

Experimentally found necessary parameters for Slack, Skype, Telegram: ... ChannelConversationId only necessary Slack, otherwise the message will be added @userAddress.

Message message = new Message 
{ 
    ChannelConversationId = channelConversationId, 
    From = new ChannelAccount 
    { 
    ChannelId = channelId, 
    Address = botAddress, 
    IsBot = true 
    }, 
    To = new ChannelAccount 
    { 
    ChannelId = channelId, 
    Address = userAddress 
    }, 
    Text = text 
}; 

を引用、(前述の)属性replyToMessageIdchannelConversationIdは必要ありません、a GitHub issueに投稿されています。彼らは内の最後の見てのメッセージを参照してください。会話中に変化します。