microsoftbotframework icon indicating copy to clipboard operation
microsoftbotframework copied to clipboard

Interface with securitybot advice

Open juju4 opened this issue 8 years ago • 2 comments

Hello,

I'm looking to use microsoftbotframework with dropbox securitybot (https://github.com/dropbox/securitybot)

Chat wrapper seems very simple https://github.com/dropbox/securitybot/blob/master/securitybot/chat/chat.py

mapping to microsoftbot

  • connect: MsBot class
  • get_users: GetConversationMembers or GetActivityMembers
  • get_messages: ???
  • send_message: CreateConversation, SendToConversation or ReplyToActivity
  • message_user: same than send_message?

advices? mostly how to get_messages? is there a recommendation between Conversation or Activity, especially depending on Target platform? (Skype, Teams...)

Thanks

juju4 avatar Aug 20 '17 15:08 juju4

Hey Julien,

The tricky parts is how the BotFramework works. Microsoft pushes a message to the MsBot object (Extended Flask Object) every time a user messages within the chat. You can store this message by using state. The examples below use JsonState but I would recommend MongodbState.

To get the user id's and also the channel / conversation ids you will probably have to use the state as well.

To send messages you will want to use SendToConversation and CreateConversation if it is the first time messaging the user. This should be the same on all of the platforms.

These are my rough notes on how I would do each.

chat.py

class Chat(object):
    def connect(self):
        self.state = JsonState()

        # See notes below regarding these 2 lines.
        self.bot = MsBot()
        self.bot.run()   # blocking

    def get_users(self):
        past_messages = self.state.get_activities()
        # find the last few conversation_ids that the bot has been in
        # call GetConversationMembers using the conversationids found

    def get_messages(self):
        past_messages = self.state.get_activities()

    def send_message(self, channel, message):
        # There are a few more arguments that you will have to set
        # You may want/have to interrogate the past messages again as well.
        SendToConversation(conversationId=channel,
                                          text=message).send()

    def message_user(self, user, message):
        past_messages = self.state.get_activities()
        # Find the last message from that user and get the converstaion_id
        SendToConversation(conversationId=conversation_id,
                                          text=message).send()

config.json

other:
    state: JsonState

Notes on MsBot object

The MsBot object extends Flask. It creates a endpoint that the Microsoft posts to. This should really be run using gunicorn and not just MsBot.run(). You may want to create 2 applications. One using the MsBot object which you can run using gunicorn and it would write out the message logs to the state file. This would then allow you to extend the chat object and just read the state file.

mbrown1508 avatar Aug 21 '17 02:08 mbrown1508

Hello @Grungnie Thanks a lot for the detailed feedback! I'm reviewing that and hopefully do some kind of tests/poc and come back to you.

juju4 avatar Aug 21 '17 10:08 juju4