IBM-Cloud / openwhisk-slackapp

A serverless Slack app built with Slack Events API and IBM Cloud Functions
Other
27 stars 28 forks source link

Slack authorisation failure #1

Closed iainhouston closed 7 years ago

iainhouston commented 8 years ago

In step 8 myserverlessapp would like to access MyTeam but encounters a failure as follows:

<errorResponse>
<httpCode>500</httpCode>
<httpMessage>Internal Server Error</httpMessage>
<moreInformation>
{ "errorMessage":"Cannot read property 'success' of undefined", "errorCode":"0x8580005c", "errorDescription":"GatewayScript console log message.", "errorSuggestion":"GatewayScript console log message. Refer to the message for more information." }
</moreInformation>
</errorResponse>

I've checked and double checked all the steps and all the OpenWhisk and Slack credentials have been properly substituted into the gateway properties of openwhisk-slackapp-api.yaml => source of openwhisk-slackapp-api 1.0.0

There is a slight difference in the UI at https://misfitstheatre.slack.com/oauth/... in that I am being asked to select a channel (in the correct team) to post to.

drptbl commented 8 years ago
<errorResponse>
<httpCode>500</httpCode>
<httpMessage>Internal Server Error</httpMessage>
<moreInformation>
{ "errorMessage":"Cannot read property 'success' of undefined", "errorCode":"0x8580005c", "errorDescription":"GatewayScript console log message.", "errorSuggestion":"GatewayScript console log message. Refer to the message for more information." }
</moreInformation>
</errorResponse>

@l2fprod @iainhouston Same error here, did everything step-by-step without any confusion. Something has changed and it's not valid anymore I guess? However, everything is properly described :+1: .

Also, just to be sure.. cloudant_url should look like that: set CLOUDANT_url=https://mykey-bluemix.cloudant.com/, with / at end, right?

Thanks for great work!

l2fprod commented 8 years ago

@iainhouston @drptbl

I just went through all the steps now with no issue and did not have to select any channel. Could you screenshot the steps where it asks for a channel?

The error message points to the code that extracts the result from the call to the OpenWhisk action "slackbot-register".

Can you check the logs of the activations? Find the activation IDs with "wsk activation list slackbot-register" then "wsk activation get ". There might be something wrong there.

drptbl commented 8 years ago

@l2fprod it didn't ask for any channel here, everything went like you've described in repo. I'm quite sure that was caused because @iainhouston ticked incoming webhook while doing "Slack button" step.

However.. I did all steps again (but this time on MAC, not Windows - not sure if that matters), also using different cloudant_url from scratch.. and my error is different now (so error mentioned before was caused by something specific for Windows or wrong cloudant_url).

After using slack button to add app to my team I'm getting this error on web:

{
status: 502,
reason: "Bad Gateway",
registration: {
activationId: "b915405e08d74954b4ad86744fc2e495",
success: false,
status: "application error"
}
}

console:

Activation: slackapp-register (some-id-here)
[
  "2016-08-31T10:02:51.749415642Z stdout: Registering new bot from Slack",
  "2016-08-31T10:02:51.76612161Z  stdout: { cloudantUrl: 'https://edited-bluemix.cloudant.com',",
  "2016-08-31T10:02:51.766156189Z stdout: cloudantDb: 'registrations',",
  "2016-08-31T10:02:51.766170466Z stdout: registration:",
  "2016-08-31T10:02:51.766182624Z stdout: { access_token: 'xoxp-edited',",
  "2016-08-31T10:02:51.766194975Z stdout: team_id: 'edited',",
  "2016-08-31T10:02:51.766206842Z stdout: scope: 'identify,bot,commands',",
  "2016-08-31T10:02:51.766216722Z stdout: user_id: 'edited',",
  "2016-08-31T10:02:51.766225986Z stdout: team_name: 'edited',",
  "2016-08-31T10:02:51.766235325Z stdout: bot:",
  "2016-08-31T10:02:51.766244495Z stdout: { bot_user_id: 'edited',",
  "2016-08-31T10:02:51.766253845Z stdout: bot_access_token: 'xoxb-edited' },",
  "2016-08-31T10:02:51.766265879Z stdout: ok: true } }",
  "2016-08-31T10:02:52.924270938Z stdout: Looking for previous registrations for the team edited"
]

(note that bot: is empty, is that fine?)

However I'm able to see bot added to my team and while I'm trying to direct message it, I'm getting this error:

Activation: slackapp-event (some-id-here)
[
  "2016-08-31T10:07:00.340861042Z stdout: Processing new bot event from Slack { cloudantUrl: 'https://edited-bluemix.cloudant.com',",
  "2016-08-31T10:07:00.34093968Z  stdout: cloudantDb: 'registrations',",
  "2016-08-31T10:07:00.340952774Z stdout: event:",
  "2016-08-31T10:07:00.340967233Z stdout: { team_id: 'edited',",
  "2016-08-31T10:07:00.340977669Z stdout: event:",
  "2016-08-31T10:07:00.340987702Z stdout: { channel: 'edited',",
  "2016-08-31T10:07:00.340997452Z stdout: ts: '1472638018.000003',",
  "2016-08-31T10:07:00.341007125Z stdout: text: 'just testing',",
  "2016-08-31T10:07:00.341016697Z stdout: event_ts: '1472638018.000003',",
  "2016-08-31T10:07:00.341026545Z stdout: type: 'message',",
  "2016-08-31T10:07:00.341036042Z stdout: user: 'edited' },",
  "2016-08-31T10:07:00.341045608Z stdout: api_app_id: 'edited',",
  "2016-08-31T10:07:00.341058986Z stdout: authed_users: [ 'edited' ],",
  "2016-08-31T10:07:00.341069299Z stdout: token: 'edited',",
  "2016-08-31T10:07:00.341079058Z stdout: type: 'event_callback' } }",
  "2016-08-31T10:07:00.416590528Z stdout: Looking up bot info for team edited",
  "2016-08-31T10:07:00.490900314Z stdout: Error { Error: one of _view, _design, _reader is required for this request",
  "2016-08-31T10:07:00.4909345Z   stdout: at Request._callback (/nodejsAction/node_modules/nano/lib/nano.js:248:15)",
  "2016-08-31T10:07:00.49094683Z  stdout: at Request.self.callback (/nodejsAction/node_modules/request/request.js:200:22)",
  "2016-08-31T10:07:00.490957308Z stdout: at emitTwo (events.js:106:13)",
  "2016-08-31T10:07:00.490973485Z stdout: at Request.emit (events.js:191:7)",
  "2016-08-31T10:07:00.490983239Z stdout: at Request.\u003canonymous\u003e (/nodejsAction/node_modules/request/request.js:1067:10)",
  "2016-08-31T10:07:00.490993853Z stdout: at emitOne (events.js:101:20)",
  "2016-08-31T10:07:00.49100384Z  stdout: at Request.emit (events.js:188:7)",
  "2016-08-31T10:07:00.491013571Z stdout: at IncomingMessage.\u003canonymous\u003e (/nodejsAction/node_modules/request/request.js:988:12)",
  "2016-08-31T10:07:00.491024149Z stdout: at emitNone (events.js:91:20)",
  "2016-08-31T10:07:00.49103357Z  stdout: name: 'Error',",
  "2016-08-31T10:07:00.491043092Z stdout: error: 'unauthorized',",
  "2016-08-31T10:07:00.491052736Z stdout: reason: 'one of _view, _design, _reader is required for this request',",
  "2016-08-31T10:07:00.491062648Z stdout: scope: 'couch',",
  "2016-08-31T10:07:00.491072159Z stdout: statusCode: 401,",
  "2016-08-31T10:07:00.491081603Z stdout: request:",
  "2016-08-31T10:07:00.491090931Z stdout: { method: 'POST',",
  "2016-08-31T10:07:00.491105719Z stdout: headers:",
  "2016-08-31T10:07:00.491115931Z stdout: { 'content-type': 'application/json',",
  "2016-08-31T10:07:00.491125459Z stdout: accept: 'application/json' },",
  "2016-08-31T10:07:00.491135598Z stdout: uri: 'https://some-id-here-bluemix.cloudant.com/registrations/_design/bots/_view/by_team_id',",
  "2016-08-31T10:07:00.49115748Z  stdout: qs: { limit: 1, include_docs: true },",
  "2016-08-31T10:07:00.491167866Z stdout: body: '{\"keys\":[\"T024FS68T\"]}' },",
  "2016-08-31T10:07:00.491177819Z stdout: headers:",
  "2016-08-31T10:07:00.49118707Z  stdout: { 'x-couch-request-id': '95dff996f2',",
  "2016-08-31T10:07:00.491196954Z stdout: 'www-authenticate': 'Basic realm=\"Cloudant Private Database\"',",
  "2016-08-31T10:07:00.491206793Z stdout: date: 'Wed, 31 Aug 2016 10:07:00 GMT',",
  "2016-08-31T10:07:00.491226133Z stdout: 'content-type': 'application/json',",
  "2016-08-31T10:07:00.491235875Z stdout: connection: 'close',",
  "2016-08-31T10:07:00.49124525Z  stdout: 'cache-control': 'must-revalidate',",
  "2016-08-31T10:07:00.4912549Z   stdout: 'x-content-type-options': 'nosniff',",
  "2016-08-31T10:07:00.491264726Z stdout: 'x-cloudant-backend': 'bm-dal-standard2',",
  "2016-08-31T10:07:00.491274712Z stdout: via: '1.1 lb1.bm-dal-standard2 (Glum/1.28.0)',",
  "2016-08-31T10:07:00.49128428Z  stdout: 'strict-transport-security': 'max-age=31536000',",
  "2016-08-31T10:07:00.491293906Z stdout: statusCode: 401,",
  "2016-08-31T10:07:00.49130335Z  stdout: uri: 'https://edited-bluemix.cloudant.com/registrations/_design/bots/_view/by_team_id' },",
  "2016-08-31T10:07:00.491313247Z stdout: errid: 'non_200',",
  "2016-08-31T10:07:00.491322673Z stdout: description: 'couch returned 401' }"
]

What's wrong?

I've tried two variations of cloudant_url's (there is no information how it should look like, I think it's worth adding), both produces same error as mentioned above. CLOUDANT_url=https://some-id-here-bluemix.cloudant.com CLOUDANT_url=https://some-id-here-bluemix.cloudant.com/ Which one is correct?

also there is a console log with case while using slash command:

Activation: slackapp-command (some-id-here)
[
  "2016-08-31T10:13:39.67515261Z  stdout: Processing new bot command from Slack { cloudantUrl: 'https://some-id-here-bluemix.cloudant.com',",
  "2016-08-31T10:13:39.675229633Z stdout: cloudantDb: 'registrations',",
  "2016-08-31T10:13:39.675242734Z stdout: command:",
  "2016-08-31T10:13:39.675252622Z stdout: { channel_name: 'directmessage',",
  "2016-08-31T10:13:39.675262185Z stdout: team_id: 'edited',",
  "2016-08-31T10:13:39.675272092Z stdout: response_url: 'https://hooks.slack.com/commands/edited/edited/edited',",
  "2016-08-31T10:13:39.675281782Z stdout: text: 'just testing',",
  "2016-08-31T10:13:39.675291302Z stdout: command: '/routine_reply',",
  "2016-08-31T10:13:39.67530078Z  stdout: user_id: 'edited',",
  "2016-08-31T10:13:39.675316053Z stdout: channel_id: 'edited',",
  "2016-08-31T10:13:39.675326022Z stdout: token: 'edited',",
  "2016-08-31T10:13:39.675335494Z stdout: team_domain: 'edited',",
  "2016-08-31T10:13:39.675344913Z stdout: user_name: 'edited' } }",
  "2016-08-31T10:13:39.796623862Z stdout: Looking up bot info for team edited",
  "2016-08-31T10:13:39.860420681Z stdout: Error { Error: one of _view, _design, _reader is required for this request",
  "2016-08-31T10:13:39.860466585Z stdout: at Request._callback (/nodejsAction/node_modules/nano/lib/nano.js:248:15)",
  "2016-08-31T10:13:39.860478771Z stdout: at Request.self.callback (/nodejsAction/node_modules/request/request.js:200:22)",
  "2016-08-31T10:13:39.860488901Z stdout: at emitTwo (events.js:106:13)",
  "2016-08-31T10:13:39.860498655Z stdout: at Request.emit (events.js:191:7)",
  "2016-08-31T10:13:39.860508127Z stdout: at Request.\u003canonymous\u003e (/nodejsAction/node_modules/request/request.js:1067:10)",
  "2016-08-31T10:13:39.860519073Z stdout: at emitOne (events.js:101:20)",
  "2016-08-31T10:13:39.860528478Z stdout: at Request.emit (events.js:188:7)",
  "2016-08-31T10:13:39.860538032Z stdout: at IncomingMessage.\u003canonymous\u003e (/nodejsAction/node_modules/request/request.js:988:12)",
  "2016-08-31T10:13:39.860547873Z stdout: at emitNone (events.js:91:20)",
  "2016-08-31T10:13:39.860557083Z stdout: name: 'Error',",
  "2016-08-31T10:13:39.860566366Z stdout: error: 'unauthorized',",
  "2016-08-31T10:13:39.860575692Z stdout: reason: 'one of _view, _design, _reader is required for this request',",
  "2016-08-31T10:13:39.860585166Z stdout: scope: 'couch',",
  "2016-08-31T10:13:39.860594402Z stdout: statusCode: 401,",
  "2016-08-31T10:13:39.860603903Z stdout: request:",
  "2016-08-31T10:13:39.860613082Z stdout: { method: 'POST',",
  "2016-08-31T10:13:39.86062221Z  stdout: headers:",
  "2016-08-31T10:13:39.860631642Z stdout: { 'content-type': 'application/json',",
  "2016-08-31T10:13:39.860641293Z stdout: accept: 'application/json' },",
  "2016-08-31T10:13:39.860651495Z stdout: uri: 'https://some-id-here-bluemix.cloudant.com/registrations/_design/bots/_view/by_team_id',",
  "2016-08-31T10:13:39.860661187Z stdout: qs: { limit: 1, include_docs: true },",
  "2016-08-31T10:13:39.860680435Z stdout: body: '{\"keys\":[\"edited\"]}' },",
  "2016-08-31T10:13:39.860691015Z stdout: headers:",
  "2016-08-31T10:13:39.860700241Z stdout: { 'x-couch-request-id': '4bf4d2f04b',",
  "2016-08-31T10:13:39.860709668Z stdout: 'www-authenticate': 'Basic realm=\"Cloudant Private Database\"',",
  "2016-08-31T10:13:39.860719316Z stdout: date: 'Wed, 31 Aug 2016 10:13:39 GMT',",
  "2016-08-31T10:13:39.8607287Z   stdout: 'content-type': 'application/json',",
  "2016-08-31T10:13:39.860738299Z stdout: connection: 'close',",
  "2016-08-31T10:13:39.860747614Z stdout: 'cache-control': 'must-revalidate',",
  "2016-08-31T10:13:39.860757136Z stdout: 'x-content-type-options': 'nosniff',",
  "2016-08-31T10:13:39.860766656Z stdout: 'x-cloudant-backend': 'bm-dal-standard2',",
  "2016-08-31T10:13:39.860776546Z stdout: via: '1.1 lb3.bm-dal-standard2 (Glum/1.28.0)',",
  "2016-08-31T10:13:39.860785991Z stdout: 'strict-transport-security': 'max-age=31536000',",
  "2016-08-31T10:13:39.860795343Z stdout: statusCode: 401,",
  "2016-08-31T10:13:39.860804738Z stdout: uri: 'https://some-id-here-bluemix.cloudant.com/registrations/_design/bots/_view/by_team_id' },",
  "2016-08-31T10:13:39.86081431Z  stdout: errid: 'non_200',",
  "2016-08-31T10:13:39.860823697Z stdout: description: 'couch returned 401' }"
]

edit: I'm testing this on my own Slack, so I have admin rights.

Looks like some error related to cloudant? Maybe it's still problem with not valid url? What is proper format for cloudant_url?

screen shot 2016-08-31 at 13 27 39
l2fprod commented 8 years ago

@drptbl the cloudant url should be of the form https://username:password@xxxxx-bluemix.cloudant.com. It is the "url" value of the "credentials". You can find it under "Service Credentials" in the Bluemix console.

drptbl commented 8 years ago

I was missing username:password@ part in cloudant url in local.env file.

It works perfectly now.

All errors posted above were caused by wrong cloudant_url. I think it's worth to update README.md file 👍 .

Thanks for help @l2fprod . Cheers!