Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface with securitybot advice #12

Open
juju4 opened this issue Aug 20, 2017 · 2 comments
Open

Interface with securitybot advice #12

juju4 opened this issue Aug 20, 2017 · 2 comments

Comments

@juju4
Copy link

juju4 commented Aug 20, 2017

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

@mbrown1508
Copy link
Owner

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.

@juju4
Copy link
Author

juju4 commented Aug 21, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants