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

How to test bot/directline locally with custom client

Open SamuelTassell opened this issue 10 years ago • 12 comments

Hi Guys,

So currently I have:

  1. One server running my BOT
  2. Another running my APP using the Direct Line API talking to my BOT
  3. CLIENT view on a mobile talking to my APP

I can run the APP and CLIENT locally, but how do I use or spoof the Direct Line API to test locally? It's a bit of a pain to keep changing the bot and upload just to test the Direct Line API.

Just to be clear, this is a custom client. How does the Emulator work locally for example? Any help would be great and let me know if I'm being stupid 😄.

Cheers.

SamuelTassell avatar Oct 09 '16 12:10 SamuelTassell

Hi @SamuelTassell. I often use ngrok to expose my local bot to the Internet. This way I can use the DirectLine API and receive the messages in my local bot. If I understand your question, this is what you're looking for. I agree that it would be GREAT if the emulator could expose a DirectLine-compatible http endpoint.

More about ngrok and the emulator: https://docs.botframework.com/en-us/tools/bot-framework-emulator/#using-the-emulator-with-ngrok-to-interact-with-your-bot-in-the-cloud

palmerabollo avatar Oct 10 '16 19:10 palmerabollo

Hi @palmerabollo, I was aware of ngrok. I can't say I've used it but what I'm really after is a way to talk to my bot with my custom client without the Direct Line API, mainly for testing locally but I'm finding the Direct Line API rubbish to work with generally 😄

SamuelTassell avatar Oct 11 '16 22:10 SamuelTassell

I'm using Postman to test Direct Line api locally. It's very easy I have 3 requests:

  1. POST https://directline.botframework.com/api/conversations Headers: Authorization BotConnector 'direct line secret' Content-Type application/json

This returns to me a conversation id and secret token

2.POST https://directline.botframework.com/api/conversations/'your_conversation_id'/messages Headers: Authorization BotConnector 'your_secret_token' Content-Type application/json Body: { "text": "hello", "Type": "message", "from": "me" }

3.GET https://directline.botframework.com/api/conversations/'your_conversation_id'/messages Headers: Authorization BotConnector 'your_secret_token' Content-Type application/json

The response will be a message from bot. Hope it helps.

irynabond avatar Oct 19 '16 19:10 irynabond

A few good suggestions here. Closing this. @SamuelTassell if none of these suggestions worked for you please open a new issue.

eanders-ms avatar Oct 25 '16 16:10 eanders-ms

@eanders-MS @irynabond So it seems its has no relation with bot running locally. Urls are pointing to directline.*** and not localhost.

Q1: How does it work with local bot? Can the conversation handled locally ? [I guess not]

Q2: Where is this conversation happening ? And where the bot logic to be placed so that directline conversations can be handled ?

ronak-itility avatar May 19 '17 16:05 ronak-itility

@palmerabollo What do you mean by "receive the messages in my local bot" ? Do you send request to the https://directline.botframework.com/... and receive a response from a bot running locally?

martabrzeszczyk avatar Jul 01 '17 22:07 martabrzeszczyk

@martabrzeszczyk Yes, exactly. You can use any external channel (telegram, slack, facebook, directline...) and your local-running bot receives all the requests.

palmerabollo avatar Jul 02 '17 07:07 palmerabollo

@palmerabollo thanks, it works for me. @ronak-itility It does relate to a bot running locally.

My case:

  1. Start a server locally. if (useEmulator) { var restify = require('restify'); var server = restify.createServer(); server.listen(3979, function() { Winston.log('info', 'test bot endpont at http://localhost:3979/api/messages'); }); server.post('/api/messages', connector.listen());
  2. Expose localhost:3979 using ngrok.
  3. Change messaging url in the Azure Bot configuration page: Configuration -> Messaging endpoint -> https URL.

martabrzeszczyk avatar Jul 02 '17 13:07 martabrzeszczyk

Is it possible to have a conversation in particular flow in ms chat bot? i am using luis, I want a single luis utterance to have different response in a particular conversation flow, how can i do it? because my utterance hits to a single intent and luis can give a single response everytime. please give solution for C# code.

NehaShaikh786 avatar Jul 05 '17 14:07 NehaShaikh786

@NehaShaikh786 could you please start a new issue for this?

JasonSowers avatar Jul 05 '17 16:07 JasonSowers

I'm using Postman to test Direct Line api locally. It's very easy I have 3 requests:

  1. POST https://directline.botframework.com/api/conversations Headers: Authorization BotConnector 'direct line secret' Content-Type application/json

This returns to me a conversation id and secret token

2.POST https://directline.botframework.com/api/conversations/'your_conversation_id'/messages Headers: Authorization BotConnector 'your_secret_token' Content-Type application/json Body: { "text": "hello", "Type": "message", "from": "me" }

3.GET https://directline.botframework.com/api/conversations/'your_conversation_id'/messages Headers: Authorization BotConnector 'your_secret_token' Content-Type application/json

The response will be a message from bot. Hope it helps.

Can we get intent name as a response? If there is any directline API to fetch intent name?

punithrajsn avatar Mar 05 '19 14:03 punithrajsn

Hi @punithrajsn

With the Bot Framework, Microsoft's Language Understanding Intelligent Service (LUIS) is used to determine intent. LUIS can be utilized using standard REST calls: https://westus.dev.cognitive.microsoft.com/docs/services/5819c76f40a6350ce09de1ac/operations/5819c77140a63516d81aee78

See here for different language examples: https://docs.microsoft.com/en-us/azure/cognitive-services/luis/luis-get-started-node-get-intent https://docs.microsoft.com/en-us/azure/cognitive-services/luis/luis-get-started-cs-get-intent https://docs.microsoft.com/en-us/azure/cognitive-services/luis/luis-get-started-python-get-intent

EricDahlvang avatar Mar 05 '19 17:03 EricDahlvang