Git Product home page Git Product logo

chatbot's Introduction

ChatBot

Just a Proof of Concept ;-)

  • Multiple BotRules are supported
    • BotRule Runs a delegate / Extend this rule to create custom ones
    • ConditionBotRule Runs nested Rules, in case conditions are satisfied
    • PowershellBotRule Uses the powershell
    • RandomAnswersBotRule Generates a random answer
    • ReplacementBotRule Returns a answer, that contains words from the previous conversations, and can also be used to learn something
  • Supported Conversation types:
    • Console Conversations
    • Lync Conversations
    • Text-To-Speech & Speech-Recognition Conversations
    • Any other Conversation, that implements the ChatSessionInterface
  • Supports Bot-Definition from:
    • XML
    • C#/.NET/Powershell
    • or any mixture of it
  • Visualizers, that visualize your current ruleset

Checkout the example

Image of a chatbot conversation

C# Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QXS.ChatBot;
using System.Text.RegularExpressions;

namespace QXS.ChatBot.Examples
{
    class Program
    {
        static void Main(string[] args)
        {

            ChatBot cb = new ChatBot(
                new List<BotRule>()
                {
                    new ReplacementBotRule("repeat", 40, new Regex("(please )?repeat(?<sentence> .*)", RegexOptions.IgnoreCase), new string[] { "i repeat your sentence:$r$sentence$", "$s$BotName$ repeats your sentence:$r$sentence$"}),
                    new RandomAnswersBotRule("getfeeling", 40, new Regex("how do you feel", RegexOptions.IgnoreCase), new string[] {"i feel great", "i feel tired", "i feel awful", "i feel happy"}),
                    new BotRule(
                        Name: "var_dump",
                        Weight: 200, 
                        MessagePattern: new Regex("^var_?dump$", RegexOptions.IgnoreCase),
                        Process: delegate(Match match, ChatSessionInterface session) {
                            string answer = "Variables: \n";
                            foreach (string key in session.SessionStorage.Values.Keys)
                            {
                                answer += "  " + key + " = " + session.SessionStorage.Values[key] + "\n";
                            }
                            answer += "---\n";
                            answer += "History: \n";
                            int i=0;
                            foreach (string ruleName in session.GetRuleHistory())
                            {
                                answer += "  " + (++i) + ". " + ruleName + "\n";
                            }
                            return answer;
                        }
                    ),
                    new BotRule(
                        Name: "setbotname",
                        Weight: 10, 
                        MessagePattern: new Regex("(your name is|you are) (now )?(.*)", RegexOptions.IgnoreCase),
                        Process: delegate(Match match, ChatSessionInterface session) {
                            session.SessionStorage.Values["BotName"] = match.Groups[3].Value;
                            return "My name is now " + session.SessionStorage.Values["BotName"];
                        }
                    ),
                    new BotRule(
                        Name: "getbotname",
                        Weight: 10, 
                        MessagePattern: new Regex("(who are you|(what is|say) your name)", RegexOptions.IgnoreCase),
                        Process: delegate(Match match, ChatSessionInterface session) {
                            if (!session.SessionStorage.Values.ContainsKey("BotName"))
                            {
                                return "I do not have a name";
                            }
                            if (match.Value.ToLower() == "who are you") 
                            {
                                return "i am " + session.SessionStorage.Values["BotName"];
                            }
                            return "My name is " + session.SessionStorage.Values["BotName"];
                        }
                    ),
                    new BotRule(
                        Name: "setusername",
                        Weight: 10, 
                        MessagePattern: new Regex("my name is (now )?(.*)", RegexOptions.IgnoreCase),
                        Process: delegate(Match match, ChatSessionInterface session) {
                            session.SessionStorage.Values["UserName"] = match.Groups[2].Value;
                            return "Hi " + session.SessionStorage.Values["UserName"];
                        }
                    ),
                    new BotRule(
                        Name: "getusername",
                        Weight: 20, 
                        MessagePattern: new Regex("(what is|say) my name", RegexOptions.IgnoreCase),
                        Process: delegate(Match match, ChatSessionInterface session) {
                            if (!session.SessionStorage.Values.ContainsKey("UserName"))
                            {
                                return "Sorry, but you have not told my your name";
                            }
                            return "Your name is " + session.SessionStorage.Values["UserName"];
                        }
                    ),
                    new BotRule(
                        Name: "greet",
                        Weight: 1, 
                        MessagePattern: new Regex("(hi|hello)", RegexOptions.IgnoreCase),
                        Process: delegate(Match match, ChatSessionInterface session) {
                            string answer = "Hi";

                            if (session.SessionStorage.Values.ContainsKey("UserName"))
                            {
                                answer += " " + session.SessionStorage.Values["UserName"];
                            }
                            answer += "!";
                            if (session.SessionStorage.Values.ContainsKey("BotName"))
                            {
                                answer += " I'm " + session.SessionStorage.Values["BotName"];
                            }
                            return answer;
                        }

                    )
                }
            );

            cb.TalkWith(new ConsoleChatSession());
        }
    }
}

XML Example

<?xml version="1.0" encoding="utf-8"?>
<ChatBot xmlns="http://www.qxs.ch/ChatBotSchema.xsd">
  <Rules>
     <Rule Type="ReplacementBotRule" Name="repeat-last-sentence">
      <Pattern><![CDATA[(please )?repeat the last sentence]]></Pattern>
      <Weight>45</Weight>
      <Messages>
        <Message>i repeat your sentence: $s$sentence$</Message>
        <Message>$s$BotName$ repeats your sentence: $s$sentence$</Message>
      </Messages>
    </Rule>
      
    <Rule Type="ReplacementBotRule" Name="repeat-sentence">
      <Pattern><![CDATA[(please )?repeat(?<sentence> .*)]]></Pattern>
      <Weight>40</Weight>
      <Messages>
        <Message>i repeat your sentence: $r$sentence$</Message>
        <Message>$s$BotName$ repeats your sentence: $r$sentence$</Message>
      </Messages>
      <Setters>
        <Set Key="sentence">$r$sentence$</Set>
      </Setters>
    </Rule>
      
    <Rule Type="BotRule" Name="b1">
      <Pattern><![CDATA[please say (?<word>\S+)]]></Pattern>
      <Weight>40</Weight>
      <Process><![CDATA[
      // Enter C# Code
      // AVAILABLE VARIABLES:
      //   System.Text.RegularExpressions.Match  match;
      //   QXS.ChatBot.ChatSessionInterface      session;
      return "ok, i say " + match.Groups["word"].Value;
      ]]></Process>
    </Rule>

    <Rule Type="PowershellBotRule" Name="pstest">
      <Pattern><![CDATA[powershell]]></Pattern>
      <Weight>30</Weight>
      <Script><![CDATA[
        # Enter Powershell Code
        # AVAILABLE VARIABLES:
        #   System.Text.RegularExpressions.Match $match
        #   QXS.ChatBot.ChatSessionInterface     $session
        $name = "John Doe"
        if ($session.SessionStorage.Values.ContainsKey("username")) {
          $name = $session.SessionStorage.Values["username"]
        }
      ( "Hi $name from PowerShell " + $PSVersionTable.PSVersion )
      ]]></Script>
    </Rule>
    
    <Rule Type="RandomAnswersBotRule" Name="feeling">
      <Pattern><![CDATA[how (are you|do you feel)]]></Pattern>
      <Weight>20</Weight>
      <Messages>
        <Message>i feel ok</Message>
        <Message>i am a bit bored</Message>
      </Messages>
    </Rule>

    <Rule Type="ReplacementBotRule" Name="set-username">
      <Pattern><![CDATA[(my name is|i am|i'm) (now )?(?<username>.*)]]></Pattern>
      <Weight>20</Weight>
      <Messages>
        <Message>your name is now $r$username$</Message>
        <Message>you are now $r$username$</Message>
        <Message>pleased to meet you $r$username$</Message>
      </Messages>
      <Setters>
        <Set Key="username">$r$username$</Set>
      </Setters>
    </Rule>
    
    <Rule Type="RandomAnswersBotRule" Name="get-username">
      <Pattern><![CDATA[(what is|say) my name]]></Pattern>
      <Weight>20</Weight>
      <Messages>
        <Message>i don't know your name</Message>
        <Message>who are you?</Message>
      </Messages>
    </Rule>
    
    <Rule Type="ReplacementBotRule" Name="set-botname">
      <Pattern><![CDATA[(your name is|you are) (now )?(?<botname>.*)]]></Pattern>
      <Weight>20</Weight>
      <Messages>
        <Message>my name is now $r$botname$</Message>
        <Message>i am now $r$botname$</Message>
      </Messages>
      <Setters>
        <Set Key="botname">$r$botname$</Set>
      </Setters>
    </Rule>
    
    <Rule Type="RandomAnswersBotRule" Name="get-botname">
      <Pattern><![CDATA[(who are you|(what is|say) your name)]]></Pattern>
      <Weight>20</Weight>
      <Messages>
        <Message>i do not have a name</Message>
      </Messages>
    </Rule>

    <!-- This condition fires in case a botname was set -->
    <Rule Type="ConditionBotRule" Name="botname-condition">
      <Weight>60</Weight>
      <Conditions>
        <Condition Key="botname" Operator="ContainsKey"></Condition>
      </Conditions>
      <Rules>
        <Rule Type="ReplacementBotRule" Name="get-botname">
          <Pattern><![CDATA[(who are you|(what is|say) your name)]]></Pattern>
          <Weight>20</Weight>
          <Messages>
            <Message>My name is $s$botname$</Message>
            <Message>I am $s$botname$</Message>
          </Messages>
        </Rule>
      </Rules>
    </Rule>
  
    <!-- This condition fires in case a username was set -->
    <Rule Type="ConditionBotRule" Name="username-condition">
      <Weight>60</Weight>
      <Conditions>
        <Condition Key="username" Operator="ContainsKey"></Condition>
      </Conditions>
      <Rules>
        <Rule Type="ReplacementBotRule" Name="get-username">
          <Pattern><![CDATA[(what is|say) my name]]></Pattern>
          <Weight>20</Weight>
          <Messages>
            <Message>Your name is $s$username$</Message>
            <Message>You are $s$username$</Message>
          </Messages>
        </Rule>
      </Rules>
    </Rule>

  </Rules>
</ChatBot>

chatbot's People

Contributors

philippe-laval avatar qxsch avatar vbwbm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatbot's Issues

Unable to send messages bot framework

I am unable to test bot from bot framework portal. I have hosted bot in local IIS server. It is working perfectly in emulator(I have provided App ID and password as well). But i am unable to pass the test in bot framework portal. I tried creating Facebook messenger channel which doesn't work either.

I have attached the screen shots of the problem. Any help will be highly appreciated. Thanks in advance

boterror

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.