microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

Publishing simple NodeJs BotConnector example fails #8

Closed Aleksion closed 8 years ago

Aleksion commented 8 years ago

Hi,

I've been eagerly attempting to get a very simple bot to work with the bot framework since I saw the keynote. While getting the bots to work locally is fairly straight forward, I can't seem to get them functioning in the cloud.

I've been playing around with the NodeJs framework - and I basically started mimicking the simple botConnector example: https://github.com/Microsoft/BotBuilder/blob/master/Node/examples/hello-BotConnectorBot/app.js

However, it fails with a 500 and no further information.

From what I can gather it throws an error in the processMessage function and hits the catch statement.

(I tried deploying both to azure, google app engine and heroku - all with the same result)

{
    "error": {
        "code": "ServiceError",
        "message": "*Sorry, CvrBot isn't available right now.*",
        "statusCode": 500
    }
}

I'm really excited to get this up and running :)

tomlm commented 8 years ago

What is your bot id (appId) ?

tomlm commented 8 years ago

Also, does it work with the emulator? ( http://aka.ms/bf-bc-emulator )

AlexAmin commented 8 years ago

Similar issue. I get a 403 if accessing the botbuilder using the botframework.com botconnector. I think the issue lies within BotConnectorBot.js @ line 39 - 43

 if (req.headers && req.headers.hasOwnProperty('authorization')) {
                    var tmp = req.headers['authorization'].split(' ');
var buf = new Buffer(tmp[1], 'base64');
                    var cred = buf.toString().split(':');
                    if (cred[0] == _this.options.appId && cred[1] == _this.options.appSecret) {

I can use my bot with no issues at all when using the emulator because the emulator sends a different header than the botframework.com botconnector and BotConnectorBot.js cannot find the "authorization" header in the message from the botconnector

Emulator

 { authorization: 'Basic QWxleFJhc3BiFmYWFkOA==',
  'content-type': 'application/json; charset=utf-8',
  host: 'alexamin.de',
  'content-length': '1441',
  expect: '100-continue' }

Botframework.com botconnector

  { 'x-correlating-operationid': 'syn24nvZHgU=fgtEjkT3aCTepT+wIU=',
    'content-type': 'application/json; charset=utf-8',
    host: 'alexamin.de',
    'content-length': '1077',
    expect: '100-continue' }

Could this be the issue?

tomlm commented 8 years ago

Are you registering an https endpoint? We only send the auth headers when using HTTPS, because otherwise we would be exposing your secret. But your code is still checking for the basic auth. Either remove basic auth (if you want an unsecure bot) or add register as HTTPS.

AlexAmin commented 8 years ago

I switched my server to https, now i have the authorization header but also get nothing but a 403 & "Sorry Bot isn't available right now". Still works in the emulator though!

_Correction: no 403! Just the error message. _

tomlm commented 8 years ago

Did you update your sample with AppId and AppSecret from your bot's registration portal page? Is Emulator using appId/AppSecret from portal?

AlexAmin commented 8 years ago

Yes, I'm using my own AppID & my own App Secret from the registration portal in my NodeJS script and emulator

tomlm commented 8 years ago

is this alexr***bot ? with appSecret ending in d8?, I can't seem to hit your https://removed.de:removed/api/messages registration. Is that the right url?

tomlm commented 8 years ago

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 52.29.235.61:YOURPORT at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at BotFrameworkEmulator.SessionModel.d__46.MoveNext()

AlexAmin commented 8 years ago

Yes thats all correct. What do you mean you cant seem to hit the endpoint? I can reach it on my browser & postman. It's running on ubuntu on an aws machine

tomlm commented 8 years ago

BTW: You can point the emulator directly to your endpoint, using your appId/appSecret to validate your bot directly.

AlexAmin commented 8 years ago

Yes that works, my emulator is pointed at my endpoint and its working :/

tomlm commented 8 years ago

really? hmmm.. let me spelunk in our logs and see if I can suss this out. Sorry for the trouble

AlexAmin commented 8 years ago

No worries haha, this is fun :)

kolanos commented 8 years ago

I'm experiencing the same thing, my bot's appId is makobot. Using HTTPS as well.

AlexAmin commented 8 years ago

botframework

btw: when not using HTTPS, slack also receives a 403. Webchat always receives a 403 and the emulator always works

tomlm commented 8 years ago

aha You registration is wrong Use the url that you have in the screenshot you sent me. I was able to talk to it, and what you had in your registration doesn't match that.

AlexAmin commented 8 years ago

Are you talking about the endpoint on the registration page? Those are 1:1 the same botframework2

AlexAmin commented 8 years ago

My bot IS receiving data from the microsoft backend. But isnt responding to it. It gets stuck before it reaches my code

tomlm commented 8 years ago

It can take 5 minutes for our caches to clear. The data you just received was probably me using postman.

tomlm commented 8 years ago

are you setting "Type" : "Message" on your reply?

AlexAmin commented 8 years ago

I can reproduce this though. When i try to contact my bot through slack, i receive data. (I put a console.log in BotConnectorBot.js)

AlexAmin commented 8 years ago

Can I control that? I thought slack was directly hooked up to botframework.com

tomlm commented 8 years ago

Leave your bot up, I'm going to run the connector in my debugger and figure out what is going on. :(

AlexAmin commented 8 years ago

Sure!

tomlm commented 8 years ago

oh crud. I am getting statuscode 500 from you with this as the response: {"code":"InternalError","message":"Invalid Bot Framework Message"}

AlexAmin commented 8 years ago

Yes, I get that too now. It's all stock though. I copied the sample from http://docs.botframework.com/builder/node/overview/#navtitle and installed the nodejs library using npm install --save botbuilder

tomlm commented 8 years ago

yes, well, we came in pretty hot and I'm guessing our node guy broke something at the last minute. I will track him down and get it resolved.

AlexAmin commented 8 years ago

Wooo awesome!

kolanos commented 8 years ago

@tomlm If you need another bot to test...

appId: makobot

tomlm commented 8 years ago

ok I have figured out the problem Somehow we had a regression in our switch and it is sending the json Pascal cased instead of camelCased. I will have to push a new connector build so it is probably an hour for me to resolve this.

tomlm commented 8 years ago

I just updated the service and your bot is working now. Let me know if you have any more issues, and THANK YOU for your patience.

tomlm commented 8 years ago

@kolanos makobot is working now too.

Aleksion commented 8 years ago

Hi @tomlm ,

Thx for reacting so swiftly! I had to head off to bed (european time).

I still seem to be having the problem.

My appId is: cvrbot

I've tried running it on https with my primay appSecret and appId, I've tried running it on http without the credentials and the middleware. But I still keep getting the 503 message.

Any clues?

Aleksion commented 8 years ago

This is what my server is logging:

  at=error code=H12 desc="Request timeout" method=POST path="/api/messages" host=stark-bastion-61581.herokuapp.com request_id=cdebdbb9-e486-450e-9519-40cddeea682b fwd="137.135.87.153" dyno=web.1 connect=0ms service=30002ms status=503 bytes=0 

The request is hitting the endpoint, but it doesn't get through the listen call.

Do the server have to use a specific port for it to work? ('ve tried with the different ones you are using throughout the examples)

tomlm commented 8 years ago

I am getting 503 just trying to talk to your endpoint. There is something wrong with your web configuration.

<!DOCTYPE html>

Application Error

Our code is simply a POST to your endpoint with application/json payload and basic authorization header. You can simulate using POSTMAN or curl

Aleksion commented 8 years ago

Right you are @tomlm - thx a bunch!

hussainak commented 8 years ago

@tomlm Could you please post some sample curl (with json data) for an endpoint?

tomlm commented 8 years ago

The emulator is essentially a fancy wrapper around CURL. Look at the JSON data there, it is the raw json

giriganapathy commented 8 years ago

Hello tomlm, I got the same kind of issue, when accessing form Test Bot Connection (BotConnector Framework page): { "error": { "code": "ServiceError", "message": "Sorry, CheckServiceAvailabilityApp is having a problem responding right now.", "statusCode": 500 } } And it is not working in Emulator as well. (403 Forbiden). I need your help to resolve it. And my bot id is:checkserviceavailability

Could you please reply to me as early as possible.
Thanks and Regards Giri G.

tomlm commented 8 years ago

You endpoint is registered as HTTP and we only send the security headers if your HTTPS.

Either register an HTTPS endpoint, or disable the check for appid/appsecret

From: giriganapathy [mailto:notifications@github.com] Sent: Monday, May 2, 2016 4:44 AM To: Microsoft/BotBuilder BotBuilder@noreply.github.com Cc: Tom Laird-McConnell Tom.Laird-McConnell@microsoft.com; Mention mention@noreply.github.com Subject: Re: [Microsoft/BotBuilder] Publishing simple NodeJs BotConnector example fails (#8)

Hello tomlm, I got the same kind of issue, when accessing form Test Bot Connection (BotConnector Framework page): { "error": { "code": "ServiceError", "message": "Sorry, CheckServiceAvailabilityApp is having a problem responding right now.", "statusCode": 500 } } And it is not working in Emulator as well. (403 Forbiden). I need your help to resolve it. And my bot id is:checkserviceavailability

Could you please reply to me as early as possible.

Thanks and Regards Giri G.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHubhttps://github.com/Microsoft/BotBuilder/issues/8#issuecomment-216215259

giriganapathy commented 8 years ago

Hello Tomlm, As per your advice, i have commented the below line: //server.use(bot.verifyBotFramework({ "appId": process.env.appId, "appSecret": process.env.appSecret }));

In spite of the above, i am still getting the same error: "error": { "code": "ServiceError", "message": "Sorry, CheckServiceAvailabilityApp is having a problem responding right now.", "statusCode": 500

could you please also confirm whether the below service deployed in azure is really working: http://checkserviceavailabilityvz.azurewebsites.net/api/messages

I would like to see the basic code running, before i start in-depth coding.

Appreciate your help on this. I am eagerly waiting for your reply.

giriganapathy commented 8 years ago

Hello Tomlm,

Ignore my previous message. After disabled the appId/appSecret, as below: server.use(bot.verifyBotFramework()); It worked in web-chat (using iframe with src pointing to my bot).

However, it is not working in "Test connection to your bot" section. Instead of textual response, it is sending entire json as below:

"type": "Message",
"id": "3OxiAkxtxAd",
"conversationId": "5ah4oXFz54O97ZG2Nm7RBBWP8pJX56X41Mk4L24kVENB3if",
"created": "2016-05-03T08:57:13.2238746Z",
"language": "en",
"text": "Hello...What is your name?",
"attachments": [],
"from": {
    "name": "CheckServiceAvailabilityApp ",
    "channelId": "test",
    "address": "checkserviceavailability",
    "id": "checkserviceavailability",
    "isBot": true
},
"to": {
    "name": "devportal",
    "channelId": "test",
    "address": "devportal",
    "id": "JMQ0KLCKN6R",
    "isBot": false
},
"replyToMessageId": "1wPLnMgp1XK",
"participants": [
    {
        "name": "devportal",
        "channelId": "test",
        "address": "devportal",
        "id": "JMQ0KLCKN6R",
        "isBot": false
    },
    {
        "name": "CheckServiceAvailabilityApp ",
        "channelId": "test",
        "address": "checkserviceavailability",
        "id": "checkserviceavailability",
        "isBot": true
    }
],
"totalParticipants": 2,
"mentions": [],
"channelConversationId": "checkserviceavailability",
"hashtags": []

}

Kindly help here.

tomlm commented 8 years ago

That is by design. 😁

Sent from my tumbs


From: giriganapathymailto:notifications@github.com Sent: ‎5/‎3/‎2016 2:04 AM To: Microsoft/BotBuildermailto:BotBuilder@noreply.github.com Cc: Tom Laird-McConnellmailto:Tom.Laird-McConnell@microsoft.com; Mentionmailto:mention@noreply.github.com Subject: Re: [Microsoft/BotBuilder] Publishing simple NodeJs BotConnector example fails (#8)

Hello Tomlm,

Ignore my previous message. After disabled the appId/appSecret, as below: server.use(bot.verifyBotFramework()); It worked in web-chat (using iframe with src pointing to my bot).

However, it is not working in "Test connection to your bot" section. Instead of textual response, it is sending entire json as below:

"type": "Message", "id": "3OxiAkxtxAd", "conversationId": "5ah4oXFz54O97ZG2Nm7RBBWP8pJX56X41Mk4L24kVENB3if", "created": "2016-05-03T08:57:13.2238746Z", "language": "en", "text": "Hello...What is your name?", "attachments": [], "from": { "name": "CheckServiceAvailabilityApp ", "channelId": "test", "address": "checkserviceavailability", "id": "checkserviceavailability", "isBot": true }, "to": { "name": "devportal", "channelId": "test", "address": "devportal", "id": "JMQ0KLCKN6R", "isBot": false }, "replyToMessageId": "1wPLnMgp1XK", "participants": [ { "name": "devportal", "channelId": "test", "address": "devportal", "id": "JMQ0KLCKN6R", "isBot": false }, { "name": "CheckServiceAvailabilityApp ", "channelId": "test", "address": "checkserviceavailability", "id": "checkserviceavailability", "isBot": true } ], "totalParticipants": 2, "mentions": [], "channelConversationId": "checkserviceavailability", "hashtags": []

}

Kindly help here.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHubhttps://github.com/Microsoft/BotBuilder/issues/8#issuecomment-216473269

giriganapathy commented 8 years ago

oh ok. thanks. I am able to test my chat in web chat. Its working perfectly. One quick question: How to customize the web chat header. It is showing "Chat" with the background blue. I would like to change the text "Chat"...So can u please guide me here.

giriganapathy commented 8 years ago

Hello tomlm,

Need your help again. I have registered a new bot. For some reason it is not working properly. Here is the behavior: Web chat related issues.

  1. I have enabled in web chat, and it works for first time. When I opened the web page (where the bot is embedded) again, it is not working. It is blank.
  2. I re-generated the webchat key, and tried to open the web page, and it is working. However it is failing for the next time. Bascially, it is working very first time, whenever I regenerate the web chat key.

Test the bot section: It is saying always that 👍 I am sorry, i did not understand your answser.

Bot Emulator: It is perfectly working in BotEmulator.

Other information: App Id: VZChatBotApp I have disabled the bot appId & secret keys as below in my code, since I use only http endpoint server.use(bot.verifyBotFramework());

Please help me here...

Regards, Giri G.

giriganapathy commented 8 years ago

with respect to webchat, I noticed the below behavior: it worked after deleting the below cookies, and refreshed the page: ARRAffinity UserId

To make the webchat work, I am deleting the above cookies everytime.

Can u please guide me here...

Regards, Giri G

bluekite2000 commented 8 years ago

@tomlm My app works fine when I publish it to web but I get "403 forbidden" in emulator. It used to work fine before in same project. Not sure what is happening. I reinstalled emulator and rebuilt project but it doesnt help.

tomlm commented 8 years ago

That only happens if appid/appsecret is mismatched between the appid/appsecret and your bot

From: dat nguyen [mailto:notifications@github.com] Sent: Wednesday, May 11, 2016 7:52 AM To: Microsoft/BotBuilder BotBuilder@noreply.github.com Cc: Tom Laird-McConnell Tom.Laird-McConnell@microsoft.com; Mention mention@noreply.github.com Subject: Re: [Microsoft/BotBuilder] Publishing simple NodeJs BotConnector example fails (#8)

@tomlmhttps://github.com/tomlm My app works fine when I publish it to web but I get "403 forbidden" in emulator. It used to work fine before in same project. Not sure what is happening. I reinstalled emulator and rebuilt project but it doesnt help.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHubhttps://github.com/Microsoft/BotBuilder/issues/8#issuecomment-218483895

rohitdharavath commented 8 years ago

I am getting the same issue {"code":"InternalError","message":"Invalid Bot Framework Message"} Can you tell me how to resolve it