Git Product home page Git Product logo

chatter-bot-api's Introduction

Chatter Bot API

A Mono/.NET, JAVA, Python and PHP chatter bot API that supports Cleverbot, JabberWacky and Pandorabots.

For a Ruby version, have a look at Gabriele Cirulli cleverbot-api implementation.

If you are planing using the .NET version, maybe this fork by Schumix is worth looking at.

News

2017-02-13: This project's v2 branch is an in progress refactor/cleanup effort. For now I have a working Java version that uses the new Cleverbot official API. No code breaking changes were required, except that you will now need an API Key when calling factory.create(ChatterBotType.CLEVERBOT, "YOURAPIKEY").

2017-01-04: Folks at Existor (the company behind Cleverbot) have concerns because this project goes against their terms of usage. Indeed, their service costs money (to host their huge servers for example) and this project allows users to bypass their ads. I acknowledged that this project does not makes a fair use of their service. I would be the first to be mad if someone would make an unfair use of one of my project, so I understand their positions. We agreed on this: this project will send a parameter on each request that will uniquely identify the project itself. They will collect metrics, and let the project alone if they found that the project usage does not make a big difference for them.

2015-09-21: Thanks to S.R, the python version is now also compatible with python 3.

2014-10-17: Merged a bunch of nicely arranged pull requests sent by Csaba Jakosa. Those include works done by Christian Gärtner (for the PHP version), and Arnaud Aliès (for the Python version).

2014-10-11: Moved to GitHub!

2014-08-04: The Java version is now on The Maven Central Repository. This is a request I get from time to time. I was too lazy to do it until now. But this time a user was kind enough, so I kick myself and did it (thanks Hardik!). Just add this dependency to your pom file.

2014-03-31: Cleverbot seems to stops working from time to time. You should expect it to be really unstable until I find a fix.

2014-02-02: Cleverbot stops working. Thanks to Matthew to let me know.

2013-11-15: Cleverbot stops working, they changed their API again. I am working on this.

2013-08-29: There is a bug with Cleverbot in any language right now. I will fix it as soon as possible. A bug with Cleverbot is now fixed in the new 1.3 revision release. Enjoy! (Kevin, Alienmario, Rai: Thanks to you guys for letting me know)

Download

I encourage you to download a compiled version of the library (TBA), and try the example below in this page. I tried to keep all the libraries free from dependencies, so you do not need to download anything else.

Be sure to always use the latest version of the library, as the Cleverbot/JabberWacky Web Service is changing over time. I suppose it is not meant to be public.

Maven

Just add this dependency to your pom file:

<dependency>
    <groupId>ca.pjer</groupId>
    <artifactId>chatter-bot-api</artifactId>
    <version>1.4.7</version>
</dependency>

Going further

If you like what you see, browse and comment the source code. If you found a bug or something missing, consult the Issues section before posting a new defect or a new enhancement. Also I will gladly accept Pull Requests

Disclaimer

I am not the owner of Cleverbot/JabberWacky nor Pandorabots.

My work (the Cleverbot/JabberWacky part) is based on pycleverbot, a Python bindings for the Cleverbot.

Contact

You can also let me know what you think.

Examples

Mono/.NET C#

using System;

using ChatterBotAPI;

namespace ChatterBotAPITest {
        
        class MainClass {
                
                public static void Main(string[] args) {
                        ChatterBotFactory factory = new ChatterBotFactory();
                        
                        ChatterBot bot1 = factory.Create(ChatterBotType.CLEVERBOT);
                        ChatterBotSession bot1session = bot1.CreateSession();
                        
                        ChatterBot bot2 = factory.Create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");
                        ChatterBotSession bot2session = bot2.CreateSession();
                        
                        string s = "Hi";
                        while (true) {
                                
                                Console.WriteLine("bot1> " + s);
                                
                                s = bot2session.Think(s);
                                Console.WriteLine("bot2> " + s);
                                
                                s = bot1session.Think(s);
                        }
                }
        }
}

Mono/.NET VB

Imports ChatterBotAPI

Public Class Application

        Public Shared Sub Main()
                Dim factory As ChatterBotFactory = new ChatterBotFactory()
                
                Dim bot1 As ChatterBot = factory.Create(ChatterBotType.CLEVERBOT)
                Dim bot1session As ChatterBotSession = bot1.CreateSession()
                
                Dim bot2 As ChatterBot = factory.Create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477")
                Dim bot2session As ChatterBotSession = bot2.CreateSession()
        
                Dim s As String = "Hi"
                Do While true
                
                        Console.WriteLine("bot1> " + s)
                        
                        s = bot2session.Think(s)
                        Console.WriteLine("bot2> " + s)
                                
                        s = bot1session.Think(s)
                Loop
        End Sub
End Class

JAVA

package com.google.code.chatterbotapi.test;

import com.google.code.chatterbotapi.*;

public class ChatterBotApiTest {
    
    public static void main(String[] args) throws Exception {
        ChatterBotFactory factory = new ChatterBotFactory();

        ChatterBot bot1 = factory.create(ChatterBotType.CLEVERBOT);
        ChatterBotSession bot1session = bot1.createSession();

        ChatterBot bot2 = factory.create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");
        ChatterBotSession bot2session = bot2.createSession();

        String s = "Hi";
        while (true) {

            System.out.println("bot1> " + s);

            s = bot2session.think(s);
            System.out.println("bot2> " + s);

            s = bot1session.think(s);
        }
    }
}

Python

from chatterbotapi import ChatterBotFactory, ChatterBotType

factory = ChatterBotFactory()

bot1 = factory.create(ChatterBotType.CLEVERBOT)
bot1session = bot1.create_session()

bot2 = factory.create(ChatterBotType.PANDORABOTS, 'b0dafd24ee35a477')
bot2session = bot2.create_session()

s = 'Hi'
while (1):
    
    print 'bot1> ' + s
    
    s = bot2session.think(s);
    print 'bot2> ' + s
    
    s = bot1session.think(s);

PHP

<?php
    require 'chatterbotapi.php';
    
    $factory = new ChatterBotFactory();
    
    $bot1 = $factory->create(ChatterBotType::CLEVERBOT);
    $bot1session = $bot1->createSession();
    
    $bot2 = $factory->create(ChatterBotType::PANDORABOTS, 'b0dafd24ee35a477');
    $bot2session = $bot2->createSession();
    
    $s = 'Hi';
    while (1) 
    {
        echo "bot1> $s\n";
        
        $s = $bot2session->think($s);
        echo "bot2> $s\n";
        
        $s = $bot1session->think($s);
    }
?>

chatter-bot-api's People

Contributors

christiangaertner avatar ksemenenko avatar megax avatar pierredavidbelanger avatar swiftyspiffy avatar theeptic avatar urban48 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  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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatter-bot-api's Issues

Cleverbot down

Today I downloaded the latest PHP version and Cleverbot does not work again. Is anyone having the same problem?
Thanks

403 forbidden

Got that error on cleverbot. Pandora is working great.

Change language of reply.

ChatterBotFactory factory = new ChatterBotFactory();
ChatterBot bot1 = factory.create(ChatterBotType.CLEVERBOT);
ChatterBotSession bot1session = bot1.createSession(new Locale.Builder().setLanguage("en").setRegion("US").build());

I'm using it, but the answers are not coming out in English and in other languages.

It is possible to change the language of the answers?

Pandora bot down

Hi guys,

Today suddenly Pandora bot didn't give any response in its python code.
Btw, cleverbot works well in python.
Thanks in advance!

Kahn

404 on Cleverbot

The PHP example is not working on my machine. On the PHP error log:

[Wed Jun 03 16:33:37 2015] [error] PHP Warning: fopen(http://www.cleverbot.com/webservicemin): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found\r\n in files/cleverbot/chatterbotapi.php on line 255
[Wed Jun 03 16:33:37 2015] [error] PHP Warning: stream_get_contents() expects parameter 1 to be resource, boolean given in files/cleverbot/chatterbotapi.php on line 256
[Wed Jun 03 16:33:37 2015] [error] PHP Warning: fclose() expects parameter 1 to be resource, boolean given in files/cleverbot/chatterbotapi.php on line 257

There is something wrong on the Cleverbot side?

Hang on startup

Hi. I have been using your code for quite awhile and now when I updated to v2 everything just hangs on startup. Code is below.. I am unsure why this happens.

static ChatterBotSession botSession;

ChatterBotFactory factory = new ChatterBotFactory();
ChatterBot bot = factory.create(ChatterBotType.CLEVERBOT, (API KEY HERE));
botSession = bot.createSession();

Problem with Jabberwacky

Hello,
With this code:

ChatterBotFactory factory = new ChatterBotFactory();
try {
    ChatterBot bot = factory.create(ChatterBotType.JABBERWACKY, null);
    ChatterBotSession botSession = bot.createSession();
    String ans = botSession.think("something");
} catch (Exception e) {}

String ans always is:

"if(ob== null||cc==0) return true;if(cc==13||cc==3){uniEsc1();ob.form.submit()};return true;}"

Debugging the code the problem is on Cleverbot.class:97, that is:

responseThought.setText(Utils.stringAtIndex(responseValues, 16));

It can be solved changing the text set to:

UtilsBotURL.stringAtIndex(responseValues, 50).replaceAll("\\<[^<>]*\\>", "")

However, this is an ugly solution.
I hope your answers.

Greetings!

utf8 encodnig fault in polish in cleverbot

bot1> "Te|017C nie wiesz?" should: "Też nie wiesz?"
bot2> "Ty lepiej jed|017A na PGA." should: "Ty lepiej jedź na PGA."
bot2> "W jakim mie|015Bcie?" should: "W jakim mieście?"

How to fix encodnig?

Java version wont work anymore

Im currently using the newest version in my java application but since 1 week pandorabots is not working anymore. It seems like they moved their bot site to a different domain.

Cleverbot webservicemin is down

C#, .NET 4.5, VS 2015
The url http://www.cleverbot.com/webservicemin 404'd for me, so it raised an exception:

System.Net.WebException: The remote server returned an error: (404) Not Found.
   at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at ChatterBotAPI.Utils.<Post>d__2.MoveNext()

in Utils.Post(string url, IDictionary<string, string> parameters)

Issue running chatterbotapitest.py

log:

C:\Users\vipaggar\Documents\code\GangsterBot\chatter-bot-api\python>python chatterbotapitest.py
bot1> Hi
bot2> Hi! Can I ask you a question?
Traceback (most recent call last):
File "chatterbotapitest.py", line 37, in
s = bot1session.think(s);
File "C:\Users\vipaggar\Documents\code\GangsterBot\chatter-bot-api\python\chatterbotapi.py", line 74, in think
return self.think_thought(thought).text
File "C:\Users\vipaggar\Documents\code\GangsterBot\chatter-bot-api\python\chatterbotapi.py", line 116, in think_thought
url_response = self.opener.open(self.bot.serviceUrl, data.encode('utf-8'))
File "C:\Users\vipaggar\AppData\Local\Continuum\Anaconda2\lib\urllib2.py", line 435, in open
response = meth(req, response)
File "C:\Users\vipaggar\AppData\Local\Continuum\Anaconda2\lib\urllib2.py", line 548, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\vipaggar\AppData\Local\Continuum\Anaconda2\lib\urllib2.py", line 473, in error
return self._call_chain(*args)
File "C:\Users\vipaggar\AppData\Local\Continuum\Anaconda2\lib\urllib2.py", line 407, in _call_chain
result = func(*args)
File "C:\Users\vipaggar\AppData\Local\Continuum\Anaconda2\lib\urllib2.py", line 556, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized

Php example not working

Hi..
i tested on my localhost.. chatterbotapitest.php.. but its not working... no reply form the bot..

Then, i modified the function to see the response form fopen...

$context = stream_context_create($contextParams);
$fp = fopen($url, 'rb', false, $context);
$response = stream_get_contents($fp);
echo $response;

i got the following response:
"DENIED +3000_cbfull"

fopen(http://www.cleverbot.com/webservicemin) HTTP/1.1 403 Forbidden

Hello,
After the bot has been running for some time, I suddenly get these errors:

[Sun Jan 03 06:13:00.457780 2016] [:error] [pid 12008] [client 149.154.167.200:49441] PHP Warning:  fopen(http://www.cleverbot.com/webservicemin): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden\r\n in /root/Projects/CleverRobot-Telegram-Bot/chatter-bot-api/php/chatterbotapi.php on line 306
[Sun Jan 03 06:13:00.458017 2016] [:error] [pid 12008] [client 149.154.167.200:49441] PHP Warning:  stream_get_contents() expects parameter 1 to be resource, boolean given in /root/Projects/CleverRobot-Telegram-Bot/chatter-bot-api/php/chatterbotapi.php on line 307
[Sun Jan 03 06:13:00.458108 2016] [:error] [pid 12008] [client 149.154.167.200:49441] PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /root/Projects/CleverRobot-Telegram-Bot/chatter-bot-api/php/chatterbotapi.php on line 318
[Sun Jan 03 06:13:00.591509 2016] [:error] [pid 12008] [client 149.154.167.200:49441] PHP Warning:  file_get_contents(https://api.telegram.org/bot123456789:XXXXXXXXXXXXXXXXXXXXXXXXX/sendMessage?chat_id=125874268&amp;text=&amp;parse_mode=Markdown): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request\r\n in /root/Projects/CleverRobot-Telegram-Bot/bot.php on line 223

Is it because I (might have) sent too many requests?

Getting 404 error from API

Seems like Cleverbot screwed with the API again and broke it. All requests returning 404. Just letting you know.

Webservicemin 404?

I am getting this error when I am trying to do a simple session.think(str):

java.io.FileNotFoundException: http://www.cleverbot.com/webservicemin
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1625)
    at com.google.code.chatterbotapi.Utils.post(Utils.java:71)
    at com.google.code.chatterbotapi.Cleverbot$Session.think(Cleverbot.java:59)
    at com.google.code.chatterbotapi.Cleverbot$Session.think(Cleverbot.java:99)

This is the script:

ChatterBotFactory factory = new ChatterBotFactory();

try
{
    ChatterBot bot = factory.create(ChatterBotType.CLEVERBOT);
    ChatterBotSession session = bot.createSession();

    LogHelper.info("Me > bot: Hi");
    LogHelper.info("Bot > me: " + session.think("Hi"));
}
catch (Exception e)
{
    e.printStackTrace();
}

I saw that you mentioned in #15 that the site now requires cookies, and I am mistaking that the java version isn't up to date. Not sure tho.

I got the chatter-bot-api via maven so maybe that's not up to date...?

All versions failed suddenly

Hi all,

In the old days, it worked very very well but since yesterday it seemed that every version failed.
As Python version an example, the output will be:

D:\Projects\chatter-bot-api-master\python>python chatterbotapitest.py
bot1> Hi
bot2> Hi there! What is your name?
Traceback (most recent call last):
  File "chatterbotapitest.py", line 37, in <module>
    s = bot1session.think(s);
  File "D:\Projects\5.7\chatter-bot-api-master\python\chatterbotapi.py", line 72, in think
    return self.think_thought(thought).text
  File "D:\Projects\5.7\chatter-bot-api-master\python\chatterbotapi.py", line 113, in think_thought
    url_response = self.opener.open(self.bot.serviceUrl, data.encode('utf-8'))
  File "D:\Python27\lib\urllib2.py", line 437, in open
    response = meth(req, response)
  File "D:\Python27\lib\urllib2.py", line 550, in http_response
    'http', request, response, code, msg, hdrs)
  File "D:\Python27\lib\urllib2.py", line 475, in error
    return self._call_chain(*args)
  File "D:\Python27\lib\urllib2.py", line 409, in _call_chain
    result = func(*args)
  File "D:\Python27\lib\urllib2.py", line 558, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: BAD REQUEST

Could anyone help me solve this?

Thanks in advance!

Kahn

The element type "hr" error -- JAVA

Hello,
I am hereby inform you that, this A.P.I. was working greatly however, Suddenly after today's evening when I executed the code I noticed this exception ->
[Fatal Error] :6:3: The element type "hr" must be terminated by the matching end-tag "</hr>". [20:21:53] [DiscLoader/SEVERE]: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 3; The element type "hr" must be terminated by the matching end-tag "</hr>". [20:21:53] [DiscLoader/SEVERE]: at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257) [20:21:53] [DiscLoader/SEVERE]: at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339) [20:21:53] [DiscLoader/SEVERE]: at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121) [20:21:53] [DiscLoader/SEVERE]: at com.google.code.chatterbotapi.Utils.xPathSearch(Utils.java:143) [20:21:53] [DiscLoader/SEVERE]: at com.google.code.chatterbotapi.Pandorabots$Session.think(Pandorabots.java:53) [20:21:53] [DiscLoader/SEVERE]: at com.google.code.chatterbotapi.Pandorabots$Session.think(Pandorabots.java:61)
Its my first time experiencing this kind of exception with chatter-bot-api.
This is my code ->
try { message.channel.sendMessage(bot1session.think(a));/*a is never empty or null. Its a proper English sentence.*/ }catch (Exception e1){ e1.printStackTrace(); }
Furthermore, I am using pandorabots bot.
bot1 = factory.create(ChatterBotType.PANDORABOTS, "b0dafd24ee35a477");//Code from examples.

I hope you find this report valuable and fix this exception.
Thank you

Cleverbot Webservice Link 404's

Looks like they've changed the webservice link for Cleverbot again, its now returning a 404 error.

Any idea what the new one is?

always has a b' or a b"

I don't know what I'm doing wrong this is my code

from chatterbotapi import ChatterBotFactory, ChatterBotType

factory = ChatterBotFactory()

bot1 = factory.create(ChatterBotType.CLEVERBOT)
bot1session = bot1.create_session()

bot2 = factory.create(ChatterBotType.CLEVERBOT)
bot2session = bot2.create_session()

s = 'Hi'
while (1):

    print ('bot1> ' + s)

    s = bot2session.think(s);
    print ('bot2> ' + s)

    s = bot1session.think(s);

and here is the output

bot1> Hi
bot2> b'Ja jestem ch\xc5\x82opakiem palancie.
bot1> b"That's not english.
bot2> b'Yash, it is.
bot1> b"Your last message was, but not the one before.
bot2> b'What are you doing?
bot1> b"Talking to you. What are you doing?
bot2> b'Talking with you. I think.
bot1> b"Ohhh, that was suprising.

Problem with two bots

Creating two or more cleverbot sessions will make the first one never answer any requests and freeze that thread (then the POST request times out)

Networking on main thread - Android issue

You're doing networking on the main thread with at least the Java version of Cleverbot, which means if you want to integrate this into an Android project, it will crash when being called.

I was at a hackathon the other day, and got around this by spawning a new thread, firing off an event using the greenrobot eventbus, and receiving the event on the main thread.

You can see the modified Cleverbot.java here: https://github.com/IntelliDrive/IntelliDrive-Android/blob/master/app/src/main/java/com/dglasser/intellidrive/CleverBotInterface/Cleverbot.java

And the event listener here: https://github.com/IntelliDrive/IntelliDrive-Android/blob/master/app/src/main/java/com/dglasser/intellidrive/MainActivity.java#L276

While this works, it really feels like a hack. Properly making a new thread, and then having a callback is probably the best way to do this. And even outside of Android, blocking the main thread with networking isn't very good practice.

org.xml.sax.SAXParseException; Premature end of file.

[Fatal Error] 👎-1: Premature end of file.
org.xml.sax.SAXParseException; Premature end of file.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
at com.google.code.chatterbotapi.Utils.xPathSearch(Utils.java:143)
at com.google.code.chatterbotapi.Pandorabots$Session.think(Pandorabots.java:53)
at com.google.code.chatterbotapi.Pandorabots$Session.think(Pandorabots.java:61)

Any update on this?

Any plans on fixing the keys or finding a way around them? The java source isn't wanting to work for me (even version 2.0)

Not in Packagist

Hi, so... the PHP version is not in the Packagist repository. I know it's not a big deal, but is it ever going to happen? Seeing that there's a composer.json file I thought there would be an entry already.

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.