Some changes for comments and whitespace
This commit is contained in:
Родитель
0f5a061447
Коммит
99af8b865d
|
@ -14,7 +14,7 @@ You can then interact with your hubot through any Bot Framework supported channe
|
|||
|
||||
### Additional Steps to Use Hubot in [Microsoft Teams](https://products.office.com/en-US/microsoft-teams/)
|
||||
|
||||
4. Create a Microsoft Teams app package (.zip) to upload in Teams. We recommend using the manifest editor in [Teams App Studio](https://docs.microsoft.com/en-us/microsoftteams/platform/get-started/get-started-app-studio). Include the bot's app id and password in the bots section.
|
||||
4. Create a Microsoft Teams app package (.zip) to upload in Teams. We recommend using the manifest editor in [App Studio for Microsoft Teams](https://docs.microsoft.com/en-us/microsoftteams/platform/get-started/get-started-app-studio). Include the bot's app id and password in the bots section.
|
||||
|
||||
5. In Microsoft Teams, navigate to the Store and select `Upload a custom app`. Select the zipped Teams App Package, and install the bot for personal and/or team use.
|
||||
|
||||
|
|
|
@ -25,11 +25,15 @@ class BotFrameworkAdapter extends Adapter
|
|||
@appId = process.env.BOTBUILDER_APP_ID
|
||||
@appPassword = process.env.BOTBUILDER_APP_PASSWORD
|
||||
@endpoint = process.env.BOTBUILDER_ENDPOINT || "/api/messages"
|
||||
@enableAuth = process.env.HUBOT_TEAMS_ENABLE_AUTH || 'false'
|
||||
@enableAuth = false
|
||||
console.log(process.env.HUBOT_TEAMS_ENABLE_AUTH?)
|
||||
console.log(process.env.HUBOT_TEAMS_ENABLE_AUTH == 'true')
|
||||
if process.env.HUBOT_TEAMS_ENABLE_AUTH? and process.env.HUBOT_TEAMS_ENABLE_AUTH == 'true'
|
||||
@enableAuth = true
|
||||
robot.logger.info "#{LogPrefix} Adapter loaded. Using appId #{@appId}"
|
||||
|
||||
# Initial Admins should be required when auth is enabled
|
||||
if @enableAuth == 'true'
|
||||
if @enableAuth
|
||||
if process.env.HUBOT_TEAMS_INITIAL_ADMINS
|
||||
# If there isn't a list of authorized users in the brain, populate
|
||||
# it with admins from the environment variable
|
||||
|
@ -75,10 +79,9 @@ class BotFrameworkAdapter extends Adapter
|
|||
@handleActivity activity for activity in activities
|
||||
|
||||
handleActivity: (activity) ->
|
||||
console.log(activity)
|
||||
@robot.logger.info "#{LogPrefix} Handling activity Channel:
|
||||
#{activity.source}; type: #{activity.type}"
|
||||
|
||||
console.log(activity)
|
||||
# Construct the middleware
|
||||
middleware = @using(activity.source)
|
||||
|
||||
|
@ -87,7 +90,7 @@ class BotFrameworkAdapter extends Adapter
|
|||
if not middleware.supportsAuth()
|
||||
# Return an error to the user if the message channel doesn't support authorization
|
||||
# and authorization is enabled
|
||||
if @enableAuth == 'true'
|
||||
if @enableAuth
|
||||
@robot.logger.info "#{LogPrefix} Authorization isn\'t supported for the channel error"
|
||||
text = "Authorization isn't supported for this channel"
|
||||
payload = middleware.constructErrorResponse(activity, text)
|
||||
|
@ -102,18 +105,11 @@ class BotFrameworkAdapter extends Adapter
|
|||
appId: @robot.adapter.appId
|
||||
appPassword: @robot.adapter.appPassword
|
||||
}
|
||||
middleware.toReceivable activity, teamsConnector, @enableAuth == 'true', \
|
||||
(event, unauthorizedError) =>
|
||||
# Send an unauthorized error response to the user if an error occurred
|
||||
if unauthorizedError
|
||||
@robot.logger.info "#{LogPrefix} Unauthorized user, sending error"
|
||||
text = "You are not authorized to send commands to hubot.
|
||||
To gain access, talk to your admins:"
|
||||
payload = middleware.constructErrorResponse(activity, text, true)
|
||||
@sendPayload(@robot, payload)
|
||||
return
|
||||
|
||||
if event?
|
||||
middleware.toReceivable activity, teamsConnector, @enableAuth, \
|
||||
(event, response) =>
|
||||
if response?
|
||||
@sendPayload(@robot, response)
|
||||
else if event?
|
||||
@robot.receive event
|
||||
|
||||
send: (context, messages...) ->
|
||||
|
|
|
@ -69,4 +69,4 @@ HubotQueryParts = {
|
|||
]
|
||||
}
|
||||
|
||||
module.exports = HubotQueryParts
|
||||
module.exports = HubotQueryParts
|
||||
|
|
|
@ -295,4 +295,4 @@ module.exports = {
|
|||
maybeConstructMenuInputCard,
|
||||
appendCardBody,
|
||||
appendCardActions
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,12 +70,12 @@ class MicrosoftTeamsMiddleware extends BaseMiddleware
|
|||
if authEnabled
|
||||
authorizedUsers = @robot.brain.get("authorizedUsers")
|
||||
senderUPN = getSenderUPN(user, chatMembers).toLowerCase()
|
||||
console.log(senderUPN)
|
||||
console.log(authorizedUsers)
|
||||
if senderUPN is undefined or authorizedUsers[senderUPN] is undefined
|
||||
@robot.logger.info "#{LogPrefix} Unauthorized user; returning error"
|
||||
unauthorizedError = true
|
||||
cb(null, true)
|
||||
text = "You are not authorized to send commands to hubot.
|
||||
To gain access, talk to your admins:"
|
||||
errorResponse = @constructErrorResponse(activity, text, true)
|
||||
cb(null, errorResponse)
|
||||
return
|
||||
|
||||
# Add the sender's UPN to user
|
||||
|
@ -83,12 +83,12 @@ class MicrosoftTeamsMiddleware extends BaseMiddleware
|
|||
|
||||
# Return a generic message if the activity isn't a message or invoke
|
||||
if activity.type != 'message' && activity.type != 'invoke'
|
||||
cb(new Message(user), false)
|
||||
cb(new Message(user), null)
|
||||
return
|
||||
|
||||
activity = fixActivityForHubot(activity, @robot, chatMembers)
|
||||
message = new TextMessage(user, activity.text, activity.address.id)
|
||||
cb(message, false)
|
||||
cb(message, null)
|
||||
|
||||
toSendable: (context, message) ->
|
||||
@robot.logger.info "#{LogPrefix} toSendable"
|
||||
|
|
|
@ -228,6 +228,3 @@ describe 'TextMiddleware', ->
|
|||
id: "user-id"
|
||||
name: "user-name"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -126,4 +126,3 @@ describe 'Main Adapter', ->
|
|||
expect(result).to.be.a('Array')
|
||||
expect(result.length).to.eql 1
|
||||
expect(result[0].text).to.eql "Authorization isn't supported for this channel"
|
||||
|
|
@ -705,4 +705,4 @@ describe 'HubotResponseCards', ->
|
|||
).to.not.throw()
|
||||
|
||||
# Assert
|
||||
expect(result).to.deep.equal(expected)
|
||||
expect(result).to.deep.equal(expected)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
--compilers coffee:coffee-script/register
|
||||
--require coffee-coverage/register-istanbul
|
||||
--recursive
|
||||
--recursive
|
||||
|
|
|
@ -30,4 +30,4 @@ class MockTeamsChatConnector
|
|||
send: (payload) ->
|
||||
robot.brain.set("payload", payload)
|
||||
|
||||
module.exports = MockTeamsChatConnector
|
||||
module.exports = MockTeamsChatConnector
|
||||
|
|
Загрузка…
Ссылка в новой задаче