Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #37 from MSMeMend/master
Browse files Browse the repository at this point in the history
Added brain loading for peristent brains
  • Loading branch information
Matt Stankiewicz committed Aug 28, 2018
2 parents a42662c + 7a5a541 commit 342cb8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/adapter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ class BotFrameworkAdapter extends Adapter
robot.logger.info "#{LogPrefix} Adapter loaded. Using appId #{@appId}"

# Initial Admins should be required when auth is enabled
if @enableAuth
if @initialAdmins?
# If there isn't a list of authorized users in the brain, populate
# it with admins from the environment variable
if robot.brain.get("authorizedUsers") is null
robot.logger.info "#{LogPrefix} Restricting by name, setting admins"
authorizedUsers = {}
for admin in process.env.HUBOT_TEAMS_INITIAL_ADMINS.split(",")
authorizedUsers[admin.toLowerCase()] = true
robot.brain.set("authorizedUsers", authorizedUsers)
else
throw new Error("HUBOT_TEAMS_INITIAL_ADMINS is required for authorization")
@robot.brain.on( "loaded", () =>
if @enableAuth
if @initialAdmins?
# If there isn't a list of authorized users in the brain, populate
# it with admins from the environment variable
if robot.brain.get("authorizedUsers") is null
robot.logger.info "#{LogPrefix} Restricting by name, setting admins"
authorizedUsers = {}
for admin in process.env.HUBOT_TEAMS_INITIAL_ADMINS.split(",")
authorizedUsers[admin.toLowerCase()] = true
robot.brain.set("authorizedUsers", authorizedUsers)
else
throw new Error("HUBOT_TEAMS_INITIAL_ADMINS is required for authorization")
)

@connector = new BotBuilder.ChatConnector {
appId: @appId
Expand All @@ -53,7 +55,6 @@ class BotFrameworkAdapter extends Adapter

@connector.onInvoke (events, cb) => @onInvoke events, cb


# Handles the invoke and passes an event to be handled, if needed
onInvoke: (invokeEvent, cb) ->
middleware = @using(invokeEvent.source)
Expand Down
2 changes: 2 additions & 0 deletions test/mock-robot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class MockRobot
return null
set: (key, value) ->
@data[key] = value
on: (eventType, functionToRun) ->
functionToRun()

receive: (event) ->
@brain.data["event"] = event
Expand Down

0 comments on commit 342cb8c

Please sign in to comment.