microsoft / BotBuilder-Samples

Welcome to the Bot Framework samples repository. Here you will find task-focused samples in C#, JavaScript/TypeScript, and Python to help you get started with the Bot Framework SDK!
https://github.com/Microsoft/botframework
MIT License
4.33k stars 4.86k forks source link

Can not response to my custom webchat from external webservice #2460

Closed lopejum closed 4 years ago

lopejum commented 4 years ago

Hello

The scenario (basically, I use an Azure Bot as a Bridge between text apps -Teams, Telegram, Skype, custom webchat... and my webservice that produces info as response according the arriving text from those text apps). So:

  1. Client writes a text on my custom web-chat
  2. Custom webchat requests a token to my Azure bot (using secret key of Direct line Channel)
  3. Custom webchat sends the text with token into Authorization header
  4. My bot receives the text and re-sends (forward) that text to an external webservice. (I can not wait the response)
  5. My external webservice makes some actions with this text
  6. The result of the process of that text will be the response I will try to send to my Azure bot for that conversation.

At this point I have: conversationId, userId, recipient, serviceUrl... All of them I have retrieved in my C# bot and sent as params to my webservice.

For every post request to my bot (trying to response to my writen texts by the client) I use activities end-point (depending of the Channel: directline, Telegram, Teams, Azure WebChat) like these: http://webchat.botframework.../v3/.../conversations/; http://directline.botframework..../v3/.../conversations/; https://smba.traffic.....

I send the body as {type, from, recipient, serviceUrl....} In the post request.

My questions:

  1. Is It correct/logic the return way to response to my client?
  2. If I use the https://mybot.azurewebsites.net/api/messages and I put Authorization header with directline secret key I always get an 500 Error (jwt token error)...
  3. I can not find the way to retrieve the initial token (created in every Channel app) into my C# bot (trying to send as param with the rest of the others param to compose the request post into my webservice)

Whats the best way to response from an external webservice though my bot to the client text app?

Kind regards Lope

stevkan commented 4 years ago

Hi @lopejum, a few questions for you:

I'm curious...why use an external service? Why not use the bot to do you various processing and communicate with the various app services directly from the bot utilizing the different adapters already available?

lopejum commented 4 years ago

Hello @stevkan

First, thanks a lot for your message.

I'll start with the curiosity (we're building an omnichannel intelligent conversational system framework):

  1. For commodity, we prefer, in our team, working with Python rather than Node or C#
  2. Initially, our architecture was built to work for WhatsApp and telephone call (real-time conversation) channels, based on Twilio API, between our "Bot" and the client
  3. At the moment, when you create a Azure Web App Bot, you can not find the Python language, so, we built a custom bot based on Azure Bot Services Python SDK
  4. We need to install/deploy our system, both, on-premise and cloud (so, in this way, we can use Azure Web App for Containers to deploy our modules, on cloud, or using our containers on-premises or private cloud -OpenShift-)
  5. Finally, we needed to use our "Bot" with every Azure native channel for "text" messages.

So, our final architecture is: [ABB] <--> [G] <--> [S] <--> [OS]

Let me explain every module: [AAB] [Module A -Azure Bot "Bridge"] It's a simple Azure EchoBot (C#), since we can activate any of native channels (Azure Web-Chat, custom webchat, Telegram, Teams...). This bot receives our text form any text channel and we "forward" this text to the next module [G]

[G] [Custom Gateway]: A Tornado Web Api, that has methods to receive (via websockets) binary info from Twilio telephone call, translate to text (using Azure Speech -Speech-to-Text-), and send it to module [S]. Another service that receives info from Twilio WhatsApp API info (WhatsApp channel), and send it to module [S]. And our simple service that receives text from our [AAB] and redirect to [S].

[S] [Custom Azure Python Bot SDK]: receives the text from [G], makes the hard work of processing the info (call to Azure Maps, Computer Vision, LUIS, QnA Maker, CosmosDB, Storage, etc.). This module does no have any interaction with Internet but the module [G]. And of course, this module is like a custom Azure Composer (hard logic for the dialog)

[OS] [Other Services]: As explained before: Azure Maps, Computer Vision, LUIS, QnA Maker, CosmosDB, Storage, etc.

For realtime-audio / whatsapp, no problem: We use Twilio API to response from [G]. For input texts, from azure native channels, we needed to response to the client "from [G] crossing [AAB]"... and I couldn't find the way... (Enter from Azure WebChat, Teams, Telegram,... any native channel; and response from DirectLine channel).

FINALLY, I found a "workaround" and solution for my architecture (create a new proactive service into my [AAB] module for receiving the messages that need to be sent, from my system, to the final client text app): The idea started from this blog, that was based in this info and implemented and deployed in this original azure project

So, that way, I can have any azure native text channel to send & receive messages (proactive) from my custom bot system.

Thanks a lot for your support!!

Best regards Lope

stevkan commented 4 years ago

@lopejum, I'm glad you were able to find a working solution. Closing this issue as resolved.