Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum example for replying to a message via BotFramework's REST API?

Within my Python webapp for the Microsoft Botframework, I want to reply to a message with a REST API call to /bot/v1.0/messages.

When experimenting with the emulator on my local machine, I realized that the minimum payload for the REST call is something like:

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

where "ConvId" is the id given by my local emulator in the original message (Note, that I have to send channelConversationId not conversationId).

Obviously, this is not enough for the live bot connector site. But what is a (minimum) example for replying to a message with the REST API call /bot/v1.0/messages?

I've tested different payload data, for example with attributes from, to, channelConversationId, textand language as indicated in the docs. But usually I get a 500 error:

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

When I tried to send back the original message, just with to and from swapped, I got a different 500 error:

{
  "error": {
     "code": "ServiceError",
     "message": "*Sorry, Web Chat is having a problem responding right now.*",
     "statusCode": 500
  }
}
like image 921
Stephan Avatar asked Dec 29 '25 20:12

Stephan


1 Answers

The minimum payload for an inline reply (returned as the response) is:

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

If you're posting a reply to out of band using a POST to /bot/v1.0/messages then you're correct you need a little more. Here's what I do in the Node version of the Bot Builder 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);
    }
});

Sending a reply to an existing conversation is a little complicated because you have to include all of the routing bits needed to get it back to the source conversation. Starting a new conversation is significantly easier:

// 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);
    }
});

Both examples assume that reply.text & reply.language has already been set.

like image 102
Steven Ickman Avatar answered Dec 31 '25 13:12

Steven Ickman