Click here to Skip to main content
13,140,231 members (48,302 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 17 Jan 2014

Using CleverBOT as Your Secretary on Facebook

, , 17 Jan 2014
Rate this:
Please Sign up or sign in to vote.
How to use agsXMPP and ChatterBotAPI for managing communication between users and cleverbot


How many of you have never run into a talkative friend? :-)

Recently, I have been swamped with too many useless messages from some of my Facebook contacts, and I've looked for a funny method to make them tired! I thought of using cleverbot as my secretary, in order to answer talkative humans with strange phrases (and make them tired). Obviously, behind this funny description, there are some lines of code that can be used in any environment. In particular, you can extract from prototype the code for login in facebook with C#, send message to user and handle received messages.

The goal of this tip is the description of following things:

  1. How to use the agsXMPP SDK to interact with Facebook platform. (Login, send and receive message)
  2. How to use ChatterBotAPI in order to interact with CleverBot.

I hope it will be helpful for you.


In order to extend the prototype attached to this tip, you only need to know what is XMPP protocol (and how to use C#). The structure of our prototype will be as shown in the following figure.

Using the Code

Since we use a third-party API, the code is really simple (and is self-explanatory).


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using agsXMPP;
using agsXMPP.protocol.client;
using agsXMPP.Collections;
using ChatterBotAPI;
namespace WindowsFormsApplication1
    public partial class Form1 : Form
        public Form1()

        XmppClientConnection xmpp = new XmppClientConnection("");
        ChatterBotFactory factory = new ChatterBotFactory();
        ChatterBot bot1;
        ChatterBotSession bot1session;
        private void Form1_Load(object sender, EventArgs e)
            bot1 = factory.Create(ChatterBotType.CLEVERBOT);
            bot1session = bot1.CreateSession();            
            xmpp.Username = "your_user_name"; // the username not the email 
            xmpp.Password = "your_password";
            xmpp.OnLogin += new ObjectHandler(OnLogin);
            xmpp.OnError += new ErrorHandler(xmpp_OnError);
            xmpp.OnAuthError += new XmppElementHandler(xmpp_OnAuthError);
            xmpp.OnMessage += new MessageHandler(xmpp_OnMessage);
            xmpp.AutoResolveConnectServer = false;
        void xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
            if (msg.Chatstate.ToString()=="composing")
            String a = msg.FirstChild.InnerXml;
            if (a == "")
            // from
            Console.WriteLine("Facebook: " + a);
            Jid to = msg.From;
            string s = bot1session.Think(a);                        
            agsXMPP.protocol.client.Message nmsg = new agsXMPP.protocol.client.Message();
            nmsg.Type =;
            nmsg.To = to;
            nmsg.Body = s;
            Console.WriteLine("\tClever: " + s);
        void xmpp_OnAuthError(object sender, agsXMPP.Xml.Dom.Element e)
            throw new NotImplementedException();
        void xmpp_OnError(object sender, Exception ex)
            throw new NotImplementedException();
        private void OnLogin(object sender)
            Presence p = new Presence(, "Online");
            p.Type = PresenceType.available;


Points of Interest

Here, we have described the guidelines and the code to build a prototype of bot-secretary. :-)

You need to keep in mind that, in order to have the best performance from CleverBot, you need to open one ChatterBotSession for each 'friend' you want to handle: The prototype attached handles all messages you receive with one single BotSession. So, CleverBot can think that it's talking with the same person though it is talking with all your friends.


  • 17/01/2014: First release
  • 17/01/2014: English revision made by Bruno Interlandi


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Authors

Software Developer F.lli Di Biasi SNC
Italy Italy
No Biography provided

Italy Italy
No Biography provided

You may also be interested in...


Comments and Discussions

SuggestionFix clverbot Pin
Member 1157892913-May-16 13:29
memberMember 1157892913-May-16 13:29 
PraiseRe: Fix clverbot Pin
Zenrac14-May-16 0:56
memberZenrac14-May-16 0:56 
QuestionHelp me! Pin
Ulyses Neira25-Oct-15 3:59
memberUlyses Neira25-Oct-15 3:59 
AnswerRe: Help me! Pin
luigidibiasi26-Oct-15 4:48
memberluigidibiasi26-Oct-15 4:48 
QuestionHelp :) Pin
Enzo Zenrac5-Sep-15 5:35
memberEnzo Zenrac5-Sep-15 5:35 
AnswerRe: Help :) Pin
luigidibiasi5-Sep-15 5:41
memberluigidibiasi5-Sep-15 5:41 
QuestionRe: Help :) Pin
Enzo Zenrac5-Sep-15 6:09
memberEnzo Zenrac5-Sep-15 6:09 
AnswerRe: Help :) Pin
luigidibiasi5-Sep-15 9:31
memberluigidibiasi5-Sep-15 9:31 
QuestionRe: Help :) Pin
Enzo Zenrac5-Sep-15 11:44
memberEnzo Zenrac5-Sep-15 11:44 
QuestionRe: Help :) Pin
Enzo Zenrac9-Sep-15 7:26
memberEnzo Zenrac9-Sep-15 7:26 
AnswerRe: Help :) Pin
luigidibiasi9-Sep-15 8:40
memberluigidibiasi9-Sep-15 8:40 
QuestionRe: Help :) Pin
Enzo Zenrac11-Sep-15 6:46
memberEnzo Zenrac11-Sep-15 6:46 
AnswerRe: Help :) Pin
luigidibiasi11-Sep-15 9:13
memberluigidibiasi11-Sep-15 9:13 
QuestionRe: Help :) Pin
Zenrac15-Sep-15 4:49
memberZenrac15-Sep-15 4:49 
QuestionRe: Help :) Pin
Zenrac11-May-16 7:45
memberZenrac11-May-16 7:45 
QuestionCould you update to a newer version of SDK Pin
Member 1039185915-May-14 14:10
memberMember 1039185915-May-14 14:10 
AnswerRe: Could you update to a newer version of SDK Pin
luigidibiasi23-May-14 22:57
memberluigidibiasi23-May-14 22:57 
Questionhelp please! Pin
Member 107307407-Apr-14 8:14
memberMember 107307407-Apr-14 8:14 
AnswerRe: help please! Pin
luigidibiasi30-Apr-14 4:56
memberluigidibiasi30-Apr-14 4:56 
QuestionMac Support? Pin
Member 106492246-Mar-14 8:38
memberMember 106492246-Mar-14 8:38 
AnswerRe: Mac Support? Pin
luigidibiasi11-Mar-14 23:07
memberluigidibiasi11-Mar-14 23:07 
GeneralRe: Mac Support? Pin
Member 1064922412-Mar-14 3:08
memberMember 1064922412-Mar-14 3:08 
GeneralRe: Mac Support? Pin
luigidibiasi12-Mar-14 22:43
memberluigidibiasi12-Mar-14 22:43 
Questionhelp Pin
Member 105717724-Feb-14 14:24
memberMember 105717724-Feb-14 14:24 
AnswerRe: help Pin
luigidibiasi5-Feb-14 6:21
memberluigidibiasi5-Feb-14 6:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.170915.1 | Last Updated 17 Jan 2014
Article Copyright 2014 by luigidibiasi, binterlandi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid