botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

modify user's display name webchat

Open ashay-88 opened this issue 9 years ago • 16 comments

Hi, I am passing a user's authenticated token in http request header to my bot, which is my webchat url. I wanted to pass token in userId section. But though I pass token in userID section, bot framework activity overwrites it with its own Azure token, which is not the one of mine as it comes like "Bearer sometokencode". So I tried to pass token in username field like this. string token = "test1123" string WebChatString = new WebClient().DownloadString("https://webchat.botframework.com/embed/transparentauth?s="+botSecret+"&userid=" + HttpUtility.UrlEncode(userId) + "&username=" + HttpUtility.UrlEncode(token));

I am getting token in my bot, but now when user sends any text, this token appears under his message as username because I am sending in that field. I want to know, If I can customize this, i will fetch user's first name using our API, and will put in Activity.From.Name = "APIOutput."

I tried this too.. but it doesnt let me do so.. What could be way to achieve this..

ashay-88 avatar Feb 19 '17 06:02 ashay-88

Hi @ashay-88 your scenario is becoming advanced enough that you probably want to host your own WebChat control from your own server so that you can do lookups such as these. https://github.com/Microsoft/BotFramework-WebChat

danmarshall avatar Feb 27 '17 19:02 danmarshall

Hi @danmarshall , Thanks for acknowledging. Luckily, I dont know how, web chat which was overriting anything which I sent in userid section has started accepting. I am sending our Token in that. This is how our token is. V-FfFxtMSV52YlUOHCW9EVggS_us7-Uk2ARMxzXtJqe-5prZTOVJlCd0qw8hrPGDH40bqCaz6yR4FfrjFcMEjiBtyXc_BJcf3FY3gJVBw0s4LAp21Qfmek-TYid_mwazkbPOkzL7yLbCx-YjXE5E8qQ36_ccnoBwNEuqbVHr_6iWsjw1a87rKg_NF3gPHVSu16crew8qX1Ir_yzEFFRtBkVEAicgbBxDJu_tw8uZPDhmzzSPsrk_cC-zDwn78yxJaqlaQjeX9VNBg9u_O9DqCViESidRoLWUfXQsXFqLgbBcW2YcgrCaiVTGTVKQglyfDf3VEF31qxy7x9F2feXPIAxR8XPlBnicsP7CGyxRLK8CRe8K_tNOLdWVFcf-rEU81ecjFUWc2ia3BI5fc84FUVMb4-LcREUPGaOeU5GDT3CoepCedMHVQr4X4Lxu6xkvrUhInbK-vkcmKbuMcXwTkkfF9t6izyq7R2I9QgHyNyrZRFlkcE2OW09-b6VKnG-wo-TJGZcKuYv6BUa-Al-2g6Cfbjun0mnuVSNqtVXmku3tRWthyxaICrWldwV9rhA_AkJDJS7NqTwHX5u4iKEo9XSHITx8H9PCT5APMVeCJYXTQ3OKYLyosWhJyUNodVZueHK088Vmei0tO5XzxtKNJgFQUJt5khiExst9MIUnFCWQ

If I use this, on click of send button, it says couldnt send. If I try to send token of same length as bot secret, it works. I tried to check limit.. it could send token of length 64...

My URL length comes to 822 characters considering my token. Is there any kind of restriction? my url looks like string url = https://webchat.botframework.com/embed/MyBotID?s=BOT_SECRET&userid=OUR_TOKEN_633_LENGTH&username=SOME_USER_NAME

webclient.downloadstring()

Please can you help me in this?

ashay-88 avatar Mar 02 '17 05:03 ashay-88

any update??

ashay-88 avatar Mar 10 '17 12:03 ashay-88

Hi @ashay-88 , when you see the "coudn't send" error, can you open your browser's debugger and inspect the network error message with this?

danmarshall avatar Mar 10 '17 19:03 danmarshall

Hi @danmarshall i checked on chrome. it said {error: {code: "MissingProperty", message: "Invalid 'from' field"}} error : {code: "MissingProperty", message: "Invalid 'from' field"} code : "MissingProperty" message : "Invalid 'from' field"

ashay-88 avatar Mar 22 '17 05:03 ashay-88

It appears that your userId is not coming through. Can you view-source on the page and see the userId from the URL in t he JavaScript code? for example, I added a &userId=foo to my url, and when I view-source I see this:

    <script>
        var model = {
  "userId": "foo",
  "userName": "You",
...

danmarshall avatar Mar 22 '17 05:03 danmarshall

@danmarshall yes I checked the source code, it is there. the code snippet was

<script>
    var model = {

"userId": "G1h9yhhLl5jieVUhZu5yj2XvygYo03DaVK/DCN//aVnZOeZpzR+bf0qPGwXYhUty86XmOcrVI47v+sb13Z17VTtuDeWYNi5voBOfsDbRfE8w5QjuTmOTRMC/tfYLQtQ3xItHo+WsMoNczCrKAFikofEPoIAPBz5LLmdPhtxlxof1AwrwEgn6g3WXANOrIq8dapMLnx27vY7QBKI9y4v+OvDVOBVAnOTmkgdzE7evRaypX9WCJbQXIBBBY0J6wxHP5ur0YYSc4ARdrYUbNYEx+HxbcVOp9Zu40cmw+SCm1775mV9/acTmu4zTE762lhXgKZo/L7HENDIo1AEJ6ojJYA==SpzXl8c9d8RMjIe0Q2z28y++eFOtm5vHo4Jko0soRH86FOgRnUqA6Kv4RSTdOD8KyM7jpZCK+hnVFf+N8SA1lgecZ33HUzQ5j8FPrX+6x+FC01olwN2CZi2ht088Na0XS2wAXNQvIr+AhD9JGhxRFeAjvPnVzSIRslJGywXBJtOcfFoOMNgDUKcT4SPe9UsUlHDoFeYS+KBqfySVOM022LvGAkSNaWfXroNy7Bqx1xBc+boN6iHA0mX0xqGiF1ahvs0DQCiOqeqlA+x2OGvedgKJxmIl86TNOhZfU6psJy8ulPFYyiOv50bIGjkT24iyTNXgW/JhhvXswGMcK0PyWw==", "userName": "Ashay", "botId": "mastekiis", "botIconUrl": "//bot-framework.azureedge.net/bot-icons-v1/bot-framework-default-7.png", "botName": "mastekiis", "secret": "{removed this}", "iconUrl": "//bot-framework.azureedge.net/bot-icons-v1/bot-framework-default-7.png", "directLineUrl": "https://webchat.botframework.com/v3/directline", "webSocketEnabled": "false" };

Seems that this error appeared earlier too #124 and #241

but no solution as such I could find. pls suggest,

ashay-88 avatar Mar 22 '17 07:03 ashay-88

Thanks for the info @ashay-88 . It seems that there is currently a max length of 64 characters for user id and 256 characters for user name.

danmarshall avatar Mar 22 '17 19:03 danmarshall

Is there any work around we can do?

ashay-88 avatar Mar 23 '17 07:03 ashay-88

Yes, you should take a look at the BackChannel feature of WebChat. We have open-sourced the WebChat with samples so that scenarios like yours can be enabled.

danmarshall avatar Mar 23 '17 18:03 danmarshall

Hi, I'm having the exact same issue. My chatbot is inside a website that needs Azure authentication, and only authenticated users can talk to the bot.

I tried passing the login information in username=email and userid=token but the token is too long. So I switched the 2 (username=token, userid=email). That works fine but the problem is that every message the user sends, it lists the token under the message like this:

token

For this project I'm required to use the Web chat Iframe. Is there a way to enlarge the userid length? Or hide the username under the message?

If anyone can help me on this that would be awesome :) Thanks!

clari182 avatar Jan 17 '18 15:01 clari182

Hi Clari,

did you get any work around on this?

Kind Regards, Ashay

ashay-88 avatar Jan 24 '18 04:01 ashay-88

Hey Ashay,

yes, I had to use Directline and https://github.com/Microsoft/BotFramework-WebChat as recommended above. No other way :(

clari182 avatar Feb 28 '18 13:02 clari182

Hi,

I have found a solution to this problem:

  1. Introduce an API which will store the long userid in an intermediate table, and return a Primary Key (length < 64).

  2. You pass that PK in the userid field, use the same API in your bot's backend code to retireve the long userid using the PK from the table.

And you're done!

debnathSD avatar Oct 03 '18 06:10 debnathSD

@clari182 i am a newbee on chatbot and vue.js but i am wondering how did you manage to get the long token inside the userid with Directline.

i use Directline like this:

App( { directLine: { secret: this.directLineSecret }, botconnection: { id: 'reversed', name:token }, bot: { id: 'proces.env.botid', name:'Luca' }, resize: 'detect' }, document.getElementById('bot') )

Mwalima avatar Oct 23 '18 07:10 Mwalima

@clari182 by the way you can also use

wc-message-from wc-message-from-me display: none;

Mwalima avatar Oct 23 '18 07:10 Mwalima