How to test bot/directline locally with custom client
Hi Guys,
So currently I have:
- One server running my BOT
- Another running my APP using the Direct Line API talking to my BOT
- 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.
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
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 😄
I'm using Postman to test Direct Line api locally. It's very easy I have 3 requests:
- 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.
A few good suggestions here. Closing this. @SamuelTassell if none of these suggestions worked for you please open a new issue.
@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 ?
@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 Yes, exactly. You can use any external channel (telegram, slack, facebook, directline...) and your local-running bot receives all the requests.
@palmerabollo thanks, it works for me. @ronak-itility It does relate to a bot running locally.
My case:
- 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()); - Expose localhost:3979 using ngrok.
- Change messaging url in the Azure Bot configuration page: Configuration -> Messaging endpoint -> https URL.
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 could you please start a new issue for this?
I'm using Postman to test Direct Line api locally. It's very easy I have 3 requests:
- 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?
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