I got stuck with creating/registering a new user using jabber.net library in C#. I am using a ejabberd as server. Here is my code: private void btnCreateAccountClick(object sender, EventArgs e). S Jabber server router jid (gecko.local.net) – target Jabber server -p Jabber server router port (5347) – target Jabber server port for components -a Jabber server router auth phrase (secret) -c Jabber component jid and smtpd name (sapsmtp.local.net) – name of THIS component -r SAP system smtpd name (seahorse.local.net) – SMTP host of SAP.
Jabber-Net is a set of.NET classes for sending and receiving Extensible Messaging and Presence Protocol (XMPP), also known as the Jabber. Client connections, server component connections, presence, service discovery, and the like. So here, when Jabber client request for SRVcisco-uds.tcp.ccie.com, the DNS SRV sends the CUCM IP to Jabber client. Also it sends the port number through which the Jabber needs to contact the CUCM Server. Priority: If you are defining multiple CUCM IP, you can give priorities to each IP's, based on priorities Jabber client contact those IP. Jabber Web SDK helps you to integrate Cisco Unified Communications capabilities including voice and video, IM and Presence, voice messaging and conferencing into any browser-based application. Deliver highly secure, clear, and reliable communications within your business application.
Net::Jabber::Component - Jabber Component LibraryComponent.pm seeks to provide enough high level APIs and automation of the low level APIs that writing a Jabber Component in Perl is trivial. For those that wish to work with the low level you can do that too, but those functions are covered in the d...
/Net-Jabber-2.0 - 07 Sep 2004 01:57:03 UTC - Search in distribution- Net::Jabber - Jabber Perl Library
- Net::Jabber::XDB - Jabber XDB Library
- Net::Jabber::Protocol - Jabber Protocol Library
Jabber::Lite - Standalone library for communicating with Jabber servers.
Jabber::Lite is, as the name implies, a small 'lite' library for dealing with Jabber servers, implemented entirely in perl. Whilst it is small, it does try to be fairly complete for common tasks. Whats in the box? Jabber::Lite is able to connect to a...
/Jabber-Lite-0.8 - 13 Feb 2007 06:11:55 UTC - Search in distributionAnyEvent::XMPP - An implementation of the XMPP Protocol
This is the head module of the AnyEvent::XMPP XMPP client protocol (as described in RFC 3920 and RFC 3921) framework. AnyEvent::XMPP::Connection is a RFC 3920 conforming 'XML' stream implementation for clients, which handles TCP connect up to the res...
/AnyEvent-XMPP-0.55 - 01 Mar 2014 21:45:53 UTC - Search in distributionJabber Net C# App
JOAP::Proxy - Base class for client-side proxies of JOAP objects
All of the classes that proxy for remote JOAP objects are subclasses of JOAP::Proxy. This package defines a lot of common behavior, but almost none of it should be used directly. Consequently, the appropriate methods and such are documented in the su...
/JOAP-0.01 - 22 May 2003 23:57:35 UTC - Search in distribution- JOAP::Server - Base Class for JOAP Object Servers
Mixin::Event::Dispatch - mixin methods for simple event/message dispatch framework
Add this in as a parent to your class, and it'll provide some methods for defining event handlers ('subscribe_to_event' or 'add_handler_for_event') and calling them ('invoke_event'). Note that handlers should return 0 for a one-off handler, and 1 if ...
/Mixin-Event-Dispatch-2.000 - 14 Sep 2015 01:25:18 UTC - Search in distributionTask::POE::All - All of POE on CPAN
This task contains all distributions under the POE namespace....
/Task-POE-All-1.102 - 09 Nov 2014 11:07:41 UTC - Search in distribution/Agent-TCLI-0.032 - 03 May 2007 18:13:49 UTC - Search in distribution
Introduction
User interfaces for software applications can come in a variety of formats, ranging from command-line, graphical, web application, and even voice. While the most popular user interfaces include graphical and web-based applications, occasionally the need arises for an alternative interface. Whether due to multi-threaded complexity, concurrent connectivity, or details surrounding execution of the service, a chat bot based interface may suit the need.
Chat bots typically provide a text-based user interface, allowing the user to type commands and receive text responses. Chat bots are usually stateful services, remembering previous commands (and perhaps even conversation) in order to provide functionality. A popular example from recent Internet history is the usage of IRC chat bots, often used for monitoring chat rooms, playing games, and providing help. The same technology can be used today, but to provide even more powerful functionality, such as serving business processing requests, multi-threaded processing, or any multi-threaded task that may not be ideal within a web application. When chat bot technology is integrated with popular web services, such as Gmail / GTalk, the chatbot can be utilized securely by an even larger audience.
Objective
Jabber Not Changing Status
In this tutorial, we'll create a C# .NET Jabber chat bot, using the XMPP Jabber protocol. Our chatbot will be compatible with Gmail and run on the Gmail / GTalk XMPP server, allowing users to access the chat bot interface directly from within their Gmail account. Our C# .NET Jabber chat bot will execute commands to list the file size on its hard drive. To keep things interesting (for both the developer and the user), our chatbot will also utilize AIML to start a conversation with the user.
Example Chatbot Log via Gmail
Some Text for the Non-Humans
Also available as a YouTube video.
Gmail is the World
An often overlooked feature of Gmail is the GTalk feature, which allows users to instant message IM other Gmail users, directly from within their Gmail account. By default, Google's instant messaging uses the XMPP Jabber protocol for communication. In this manner, our chat bot can login to Gmail's XMPP server and listen for incoming requests. Any instant messages sent to the Gmail user will be forwarded to our chat bot software, allowing us to process and return a result.
Of course, we'll first need a Gmail account to host our C# .NET Jabber chat bot. You can create one by signing up to Google Gmail. After signing up, the account can be used by the C# .NET Jabber chat bot to communicate. A user who wishes to communicate with the chat bot will need to enter the name of the chat bot under the 'Chat' section in Gmail, and request an invite to talk. Once connected, the user can directly communicate with the C# .NET jabber chatbot.
Summary of the Challenge at Hand
There are a couple of technologies that need to be defined before stepping into creating the C# .NET chat bot:
Jabber is an open-source technology for communicating.
Jabber uses the XMPP protocol to communicate.
AIML is an artificial intelligence markup language.
AIML provides a system of XML files for requests and responses to communicate with a human.
We can combine Jabber XMPP with AIML and execute within Gmail to provide a fully functional and secure chatbot software application.
Speaking the Jabber Language
With the technologies defined, we can now step into creating the C# .NET Jabber chatbot. For the XMPP protocol, we'll be using the agsXMPP SDK. For our brain, AIML, we'll be using the popular ALICE SDK from the Artificial Intelligence Foundation. AIML will provide a human conversation feature for our Jabber chat bot (while business chat bots may be designed primarily to perform business tasks, it doesn't hurt to communicate like a human). To get started, we'll need to setup a connection to Gmail's XMPP service. We can do this by initializing and connecting to Gmail at talk.google.com with the following code:
Improving Configuration for the Human
Rather than providing hard-coded values for the XMPP server information, we can move this into an App.config file for easier management. This will change our code as follows:
Notice in the above code, we've provided a means for allowing the console user to enter a password when running the C# .NET chatbot. Since our program is a Windows console application, we have the option to enter the password within the App.config, or to provide a small amount of security, and have the user manually enter the password within the client application at runtime.
We can actually hide the password being typed in the C# .NET console application by using the following helper method:
The above method provides a small amount of security while entering the Gmail account password, allowing the C# .NET jabber chatbot to login to the XMPP service.
We've also refactored the XMPP configuration to take out the hard-coded server and login parameters, and have replaced them with a C# .NET custom configuration section.
Come On, You're Not Hard-Coding Login Details.. Are You?
By removing the hard-coded login details, we can implement a custom configuration section, allowing our App.config to appear as follows:
The botConfig Custom Configuration Section
We can implement the C# .NET custom configuration section with the following two classes:
With the above defined, we can access our C# .NET Jabber Gmail chatbot configuration with the following line of code:
Running Forever
Once the C# .NET Jabber chatbot is logged into the Gmail / GTalk service, we'll enter a while loop within our console application. Since we've setup event handlers to receive incoming requests and respond, we can simple leave the program running. While the ideal solution would be to create a Windows service application to host our chatbot, for simplicity, we'll leave a basic console application running.
While running, our chatbot will respond to the supplied events: OnLogin, OnError, and OnMessage. Of course, the most important event is OnMessage, indicating we've receiving an incoming instant message from a user to our chatbot.
I Hear You Loud and Clear
Upon receiving an instant message on Gmail or the Jabber service, our chatbot will execute the OnMessage event handler. Within this event, we'll process the message, to perform any service or functionality, and return an output to send back as an instant message. We can implement the OnMessage event handler as follows:
Note, in the above code we get the Gmail username from the incoming instant message. We'll use this to provide context to our chatbot. This allows our chatbot to remember conversations and state, responding accordingly to subsequent commands or conversation. AIML has built-in support for User context, although we'll still need to maintain a hashtable of users (identified by Gmail username) on our end.
Processing an Instant Message
Once we've received the instant message, we'll need to process the text for any commands that we recognize. We handle this processing within the HandleMessage() method, defined as follows:
In the above code, we simply take the incoming instant message and check for any keywords or commands that we recognize. You can use your imagination to expand this functionality to any number of tasks, such as IRC bot functionality, script execution, or any number of business process features. For enhanced architecture, you could even abstract the if-then decision into a Strategy design pattern, and with the use of reflection, allow your chatbot to respond dynamically at runtime to new commands and requests (simply by dropping a new DLL into the executable folder).
In our example, we'll simply recognize the command 'DISK SPACE' in any sentence, as well as the command 'DISK SIZE'. If found, we'll perform some processing, such as accessing the C# .NET DriveInfo object, and return the output.
If a command is not recognized, we'll pass the incoming instant message to our AIML chatbot instance to process and return a result. The result will then be sent back to the end user as a response. Of course, to process the instant message with AIML, we'll need a brain within our C# .NET Jabber chatbot.
Giving our Chatbot a Brain
Our chatbot will directly handle recognized commands and return a response manually. We've provided this functionality directly within the HandleMessage method. However, for unrecognized commands, we'll pass the instant message to our AIML bot to process. AIML will return a response in conversation format. We can create an AIML bot as follows:
In the above code, we've created a new class which wraps the AIMLbot.Bot class, provided by the AIML SDK. We initialize the C# .NET AIML bot and provide it with a list of AIML XML files (located within the /bin directory of our C# .NET console application).
Some Fancy Post-Build Steps for our Brain Files
Since AIML requires a series of XML files in order to process responses, we've included them within the Visual Studio project solution. We'll need to copy these files to the executable directory each time. We can do this automatically with a post-build event step as follows:
The above command simply copies the two folders 'aiml' and 'config' into the solution's /bin/Debug or /bin/Release folder.
Talking Back
The last method in our AIMLChatBot wrapper class is GetOutput, which simply calls the Chat() method of the AIML SDK to process and return a response. Since we pass in the User object for context, our AIML chat bot is able to provide context and specific conversation based upon each unique user. This allows our chatbot to remember the user's name, identity, and other conversation features. We can also leverage this context for business functionality and stateful service within our application.
Jabber-net C# Tutorial
Giving our Chatbot Personality
The default implementation of our C# .NET Jabber Gmail chatbot uses AIML for its 'brain', in order to provide conversation. However, the chatbot can actually be customized to provide different personality, simply by editing the AIML XML files. You can experiment by editing the files in config/ such as config/DefaultPredicates.xml to provide names and background details, etc.
Into the Future and Beyond
It may be debatable whether a particular business problem can be best solved with the use of a C# .NET Jabber chatbot, as opposed to a C# ASP .NET web application. However, particular cases for a chatbot being more feasible over a web application may involve issues regarding multi-threaded and blocking functionality. Consider the execution of a server-side script or long-running process. Within a web application, the web page would need to serve the user a waiting page and notify the user upon completion. A chatbot, however waits by nature. You send an instant message to the chatbot. Process execution begins. The chat bot has the option to reply back with status and completion. While execution in a multi-threaded environment and the associated complexity is similar to a web application's, a chatbot may offer a more streamlined solution, depending on business needs.
Another aspect of chatbot solutions is flexibility in the command-line driven user interface. The interface offers a more flexible and expressive means of executing a variety commands, often provided with less underlying framework on the developer's part.
An additional added benefit to utilizing a chatbot, particular when combined with a popular and secure service such as Gmail, is the built-in security and access-point from the 3rd-party service. This allows more users to easily access the software and execute business services without the need for hosting concerns. Of course, the chatbot itself, will still need to be hosted on a server (whether central or decentralized).
## See It In Action
Download @ GitHub
You can download the project source code on GitHub by visiting the project home page.
Conclusion
A C# .NET Jabber chat bot application, running within the context of the popular Gmail service, can provide a variety of business functionality, including execution of tasks, information gathering, and even simulated human conversation. By integrating the Jabber XMPP protocol with the AIML chatbot SDK, an application can provide an experessive user interface and interaction, possibly providing a greater human touch to traditional user interfaces.
About the Author
This article was written by Kory Becker, software developer and architect, skilled in a range of technologies, including web application development, machine learning, artificial intelligence, and data science.