DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Microservices With Apache Camel and Quarkus
  • Understanding Dependencies...Visually!
  • Competing Consumers With Spring Boot and Hazelcast
  • Microservices With Apache Camel and Quarkus (Part 3)

Trending

  • Microservices With Apache Camel and Quarkus
  • Understanding Dependencies...Visually!
  • Competing Consumers With Spring Boot and Hazelcast
  • Microservices With Apache Camel and Quarkus (Part 3)
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Connecting the Dots Between Firebase and Microsoft Bot Framework: Part II

Connecting the Dots Between Firebase and Microsoft Bot Framework: Part II

You can create a bot that puts a message into the Azure Service Bus that will trigger your NodeJS Azure function to store the data in Firebase. Pretty cool, isn't it?

Ezequiel Reyno user avatar by
Ezequiel Reyno
·
Mar. 10, 17 · Tutorial
Like (3)
Save
Tweet
Share
5.56K Views

Join the DZone community and get the full member experience.

Join For Free

In Part I of this post, I described a system with several parts, such as the connections between Firebase, AngularJS, and Azure functions. I also added new tools like Microsoft Bot Framework and Azure Service Bus to enhance our app in a decoupled way. As always, the working example is available here.

Last time, I put my focus on the NodeJS Azure function, but today, I'll describe the Microsoft Bot Framework. As I said in my last post, the idea is to create a bot that receives a place name and response with the current date time at that location. After the bot parses the input and generates the proper response, it puts a message into the Azure Service Bus that will trigger our NodeJS Azure function to store the data in Firebase. Pretty cool, isn't it? You can check the working version here.

Microsoft Bot Framework

Microsoft has created an awesome framework that allows us to create a bot — yes, a conversational tool that is able to interact with our customers. The bot itself is a web API application that can run on any web server. Then we just register our bot on the Microsoft Bot framework website. Under the configuration page, we define different channels where our bot is going to run.

And that's it! As simple as that, our bot will be able to interact with customers from Skype, Facebook chat, or Tulio.

bot

Creating the Bot

I already told you that the bot is just a web API that can run on any server. Microsoft Bot Framework has two different versions: a bot builder for .NET and a bot builder for NodeJS.

 [ResponseType(typeof(void))]
 public virtual async Task < HttpResponseMessage > Post([FromBody] Activity activity) {
  if (activity != null) {
   // one of these will have an interface and process it
   switch (activity.GetActivityType()) {
    case ActivityTypes.Message:
     await Conversation.SendAsync(activity, () => EchoChainDialog.dialog);
     break;

    case ActivityTypes.ConversationUpdate:
    case ActivityTypes.ContactRelationUpdate:
    case ActivityTypes.Typing:
    case ActivityTypes.DeleteUserData:
    case ActivityTypes.Ping:
    default:
     Trace.TraceError($ "Unknown activity type ignored: {activity.GetActivityType()}");
     break;
   }
  }
  return new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
 }

As you can see in the code above, we only need to define a POST action in our web API controller, which will be the SPOC of our bot. Every message is going to be routed to this action. In my case, based on the activity type, I let my bot respond. In this example, we are creating a new instance of the class EchoChainDialog. This dialog entity is going to handle the conversation base on what we define. In my case, I just use a switch method from the IDialog object to parse the text and response to our customer.

Azure Service Bus

I've created as well an Azure Service Bus to use as a trigger for my NodeJs Azure function. What does that mean? The idea is that after the bot processes the request and generates a response, it puts a message into the Azure Service Bus. As you can see below, the code to do that is really simple. We just need the Service Bus connection string and the queue name. When a new message arrives at this particular queue in the Azure Service Bus, it will trigger the NodeJS Azure Function we created last time. This mechanism is created and configured in Azure.

 try {
  var client = QueueClient.CreateFromConnectionString("connectionString", "queueName");
  var message = new BrokeredMessage(JsonConvert.SerializeObject(responseData));
  client.Send(message);
 } catch {}

For more details of Azure Service Bus, you can use this link. For mode details of Microsoft Bot Framework, you can use this link. For more details of Azure functions, you can use this link.

If you found this post useful, please don't forget to press the like button and share it. If you are in doubt, don't hesitate to ask a question and, as always, thank you for reading.

Framework azure Firebase Web Service Web API

Published at DZone with permission of Ezequiel Reyno. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Microservices With Apache Camel and Quarkus
  • Understanding Dependencies...Visually!
  • Competing Consumers With Spring Boot and Hazelcast
  • Microservices With Apache Camel and Quarkus (Part 3)

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: