Connecting to Microsoft Bot Framework

The following example demonstrates how to configure a Chat agent class that handles the communication between the Chat for jQuery and the Microsoft Bot Framework.

In this case, the establishment of a connection to the service and the binding of the appropriate events are done within the init method. The agent is subscribed to listen for any activity$ of the remote service. When an activity is detected, the appropriate method from the Chat public API is invoked to render the data. To handle the user input, the example implements the post event handler of the Chat and the arguments are passed to the Chat Bot service.

<div id="chat"></div>

<!-- Load Bot Framework Client API -->
<script src=""></script>

  $(document).ready(function () {
    // Initialize the Chat
    var chat = $("#chat").kendoChat({
      post: function (args) {

    // Create a new agent and pass the Chat widget
    var agent = new DirectLineAgent(chat, "Y_ly-If6haE.cwA.PQE.ZwOOsq4MlHcD3_YLFI-t9oW6L6DXMMBoi67LBz9WaWA");

  window.DirectLineAgent = kendo.Class.extend({
    init: function (chat, secret) { = chat;
      this.iconUrl = "";

      // Assign here the Bot framework agent
      // The below example uses the Microsoft's Bot Framework
      this.agent = new DirectLine.DirectLine({ secret: secret });

      // The below code would depend on the Bot framework of choice
      // In this case, the agent is subscribed to listen for any activity of the service
      // Its onResponse method would be executed on any activity detected
      this.agent.activity$.subscribe($.proxy(this.onResponse, this));
    // The implementation of the below methods would depend on the Bot framework of choice
    // This example uses the Microsoft's Bot Framework API to demonstrate a possible implementation
    postMessage: function (args) {
    onResponse: function (response) {
      if ( === {

      response.from.iconUrl = this.iconUrl;

    renderMessage: function (message) {
      if (message.text || message.type == "typing") {, message.from);
    renderAttachments: function (data) {, data.from);
    renderSuggestedActions: function (suggestedActions) {
      var actions = [];

      if (suggestedActions && suggestedActions.actions) {
        actions = suggestedActions.actions;

See Also

For runnable examples on Kendo UI Chat, refer to the Kendo UI Demos site.

In this article
Not finding the help you need? Improve this article