[OutSystems.AI Chatbot] After updating messaging endpoint - getting 401 unauthorized

Forge Component
(10)
Published on 2019-12-23 by Rui Parente
10 votes
Published on 2019-12-23 by Rui Parente

After updating messaging endpoint in Configure the bot service and customize the responses - step 9

Getting RequestUrl: https://xyzxyz-dev.outsystemscloud.com/MyChatbot/rest/MessagingWebhook_V1/PostMessage (Method: POST)

So looks like chatbot is trying to talk to Microsoft bot, which in turn is trying to hit MyChatbot - but that is failing.

Help?

Hello.

The message from that the user wrote is getting to your webhook? If you add a breakpoint and debug the webhook, do you receive the message with the sentence the user wrote in the chatbot front-end?


Bruno Martinho

Hi Bruno,

I added the breakpoint-

When I open the react web page, breakpoint hits - but fails on Is Message?  I assume this is just initializing component.

When I send first message - breakpoint hits but it doesn't actually receive a message.

When I send second message - breakpoint hits, my GetResponse Message works (I think), but then it fails on ReplyToActivity - just never gets past that.  Message is 'Failed to send actitvity: bot returned an error'

In service center, after it dies on ReplyToActivity, I see the following 4 errors in (always 4 new 401 Unauthorized)


So... looks like my web bot is hitting azure portal, which in turn is hitting chatbot module, but when that tries to return message through azure it is getting unauthorized?

I checked azure:

Direct Line has this error:
There was an error sending this message to your bot: HTTP status code InternalServerError


Also in Azure I cannot load App Service Settings->Configuration (Failed to load settings)

Okay it looks like when I change Messaging endpoint from the default bot url to https://xyzxyz-dev.outsystemscloud.com/MyChatbot/rest/MessagingWebhook_V1/PostMessage

That is when I can no longer view my Azure Settings.

I have MicrosoftClientId and MicrosoftClientSecret set correctly in Service Center, and the MyChatbot app refers to them as Site.MicrosoftClientId and Site.MicrosoftClientSecret and they show up in the message properties...

Maybe they can't verifiy against Azure since the settings cannot be loaded?


The 4 messages

First two are REST (Consume), second one has blank module, third is REST (Expose)

REST (Expose)S6G00-LT8723


In Azure: this is my messaging endpoint, which I got out of webhook.

I would say that 401 could be a wrong configuration in the MicrosoftClientId or the MicrosoftClientSecret in the Webhook.

Can you please double check the values?

In order to see that is Azure, please change the webhook link temporary in Azure for: 

https://[BOTNAMEinAZURE].azurewebsites.net/api/messages

This will allow you to check back the credentials.



Bruno Martinho wrote:

I would say that 401 could be a wrong configuration in the MicrosoftClientId or the MicrosoftClientSecret in the Webhook.

Can you please double check the values?

In order to see that is Azure, please change the webhook link temporary in Azure for: 

https://[BOTNAMEinAZURE].azurewebsites.net/api/messages

This will allow you to check back the credentials.



I changed the webhook link back to get the credentials.

MicrosoftClientId in Outsystems is same as MicrosoftAppId in Azure

MicrosoftClientSecret in Outsystems is same as MicrosoftAppPassword in Azure


I tried something else: I clicked on 'Test in Web Chat' in Azure.  This correctly hits my OS Webhook... which can't get a reply back.


Anything else to try?


Hi, can you try to debug the OnBeforeRequest action of the REST API of the AzureBotFramework module, please?

Don't forget to set the Entry Module to your Webhook espace



Follow that flow, always doing Step Into F11, to check if the service to request the access token is working correctly.

This is where the issue must be:


Here is screenshot of my Integrations->Rest


I don't have the AzureBotFramework added to the Chatbot webhook... I didn't see anything about doing that on the instructions for OS 11 - https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/Artificial_Intelligence/Setup_and_use_the_OutSystems.AI_Chatbot_component_in_your_OutSystems_applications


Did I miss something in the instructions, or ?


Here is AzureBotFrameworkConnector from Manage Depedencies


I do not have this so I cannot step into it: OnBeforeRequest action of the REST API of the AzureBotFramework module

Hello and Happy New Year.

The espace I was refering is AzureBotFrameworkConnector and no AzureBotFramework, sorry for the confusion.


In the end of your webhook you should be calling the ReplyToActivity action:


This action belong to AzureBotFrameworkConnector espace. Can you debug on this espace and add the breakpoint to  OnBeforeRequest action of the REST API.

I see the same thing, but I do not see any OnBeforeRequest.  I get to the 'GetResponseMessage' and can step into and out of that - but when I get to 'ReplyToActivity' it just dies - this is where the 401 actually happens.   I have posted image of my main logic flow, which is the same as yours, with AzureBotFrameworkConnector expanded, and a second one which shows Integrations expanded.  I don't have the AzureBotFramework as option under Integrations->REST, which is what you seem to be talking about, and are showing above.

How do I add this?  It seems like this is the missing piece.

Thanks!  Happy New Year.


Hi again.

I thought previously your screenshot was of the MyChatbot service module, when it is actually of the AzureBotFrameworkConnector  eSpace.

Once I opened that eSpace, I see what you see.  However, I am not able to debug into it.  I am unable to set the Entry Module to anything other than (this module).  So when I get to 'ReplyToActivity' and hit Step into F11, it just dies - and does not actually debug into that eSpace.

Is this an easy setup issue, to correct?

Thanks much- Josh


Solution

SOLVED!!!

TL/DR; => I updated AzureBotFrameworkConnector module to latest version and it started working.

(Read below for more of how I got there, and #7 is question for Bruno)

1) I was not able to select entry module because some of the other modules in my solution were out of date.  So, I opened each one individually and re-published them.  After I did this, I was able to select 'MyChatbot' which is my Chatbot Webhook service module as the entry module for the AzureBotFrameworkConnector espace.

2) Once I had this entry module set, I was able to debug into AzureBotFrameworkConnector espace.

3) In the screen below - it was dying (401 unauthorized) at the RequestAccessToken module, circled.

4) In lower right - ClientId just said 'MicrosoftClientId' and ClientSecret just said 'MicrosoftClientSecret'

5) I changed these values to be the actual values from my Azure bot.... and it still failed.

6) After some trial and error I had to delete AzureBotFrameworkConnector module and re-download it... voila!  There was a new version which had the EncodeUrl() around the MicrosoftClientSecret.

7) I had re-added the actual values here... Bruno, can you tell me if I can change back to MicrosoftClientId and MicrosoftClientSecret - (I have site properties loaded to MyChatbot for these through service center)


Solution

Joshua Kay wrote:


I just proved out that you don't need to put in actual values there.  The following works fine.

Mine was failing because the original version I had apparently didn't have 'EncodeUrl'.


SOLVED!!!

TL/DR; => I updated AzureBotFrameworkConnector module to latest version and it started working.

(Read below for more of how I got there, and #7 is question for Bruno)

1) I was not able to select entry module because some of the other modules in my solution were out of date.  So, I opened each one individually and re-published them.  After I did this, I was able to select 'MyChatbot' which is my Chatbot Webhook service module as the entry module for the AzureBotFrameworkConnector espace.

2) Once I had this entry module set, I was able to debug into AzureBotFrameworkConnector espace.

3) In the screen below - it was dying (401 unauthorized) at the RequestAccessToken module, circled.

4) In lower right - ClientId just said 'MicrosoftClientId' and ClientSecret just said 'MicrosoftClientSecret'

5) I changed these values to be the actual values from my Azure bot.... and it still failed.

6) After some trial and error I had to delete AzureBotFrameworkConnector module and re-download it... voila!  There was a new version which had the EncodeUrl() around the MicrosoftClientSecret.

7) I had re-added the actual values here... Bruno, can you tell me if I can change back to MicrosoftClientId and MicrosoftClientSecret - (I have site properties loaded to MyChatbot for these through service center)



Hello Joshua,

7) I had re-added the actual values here... Bruno, can you tell me if I can change back to MicrosoftClientId and MicrosoftClientSecret - (I have site properties loaded to MyChatbot for these through service center)

I've seen you got the answer, that is great.


Bruno Martinho