Reputation: 1
I'm new to the Botframework, but am making some great headway. I've got a bot up and running and it works great for DM chats in Slack, but I'd like my bot's responses to be only to asking user in a chatroom/group instead being broadcast to the group.
Reading up on Slack, it looks like if I set the response_type to "ephemeral", this should solve the problem. Sounds potentially easy enough, but no idea if we have the ability to override this in the dialog context / activity. Any suggestions?
Upvotes: 0
Views: 159
Reputation: 423
If you take a look at the NodeJS SDK Documentation for Sessions and scroll down to the Cards section, you will find a handy little function of the Message class
Message.sourceEvent()
From the same documentation page:
It’s not practical for the SDK to support every card or attachment format supported by the underlying chat service so we have a Message.sourceEvent() method that you can use to send custom messages & attachments in the channel native schema.
Which means that you can use Message.sourceEvent()
to do exactly what you are trying do: alter the structure of your outgoing message object.
Here is a code snippet for your specific case that I tried out:
//test slack source event messaging
var msg = new botbuilder.Message(session).sourceEvent({
slack: {
response_type: "ephemeral",
text: "This is a test Slack message.",
attachments: [
{
text: "Test inlaid message."
}
]
}
});
When you pass the current session
to the Message()
class, it populates all the address info in the Message so you don't have to do any of that. You can see for yourself here in the documentation for the Message's constructor method.
Then, you just call sourceEvent()
and pass in an object, with the name of the channel you are constructing a message for (in this case slack), and then fill out the desired message data. This allows you to define your response_type: "ephemeral"
.
Documentation for sourceEvent() here.
Upvotes: 1