Home > DIY, Programming > DIY Omegle Chat Bot!

DIY Omegle Chat Bot!

I have been chatting on  Omegle for quite some time now and I must say that i find it rather addictive. During one conversation, i encountered a bot and needless to say, i was hooked on to the convo ! I wanted to make one for myself badly somehow 🙂

A quick search later revealed that most of the chatter bots were based on the Artificial Intelligence Markup Language.It’s basically a rule based xml language which is used by the AI engine to give a response (a.k.a. categories) based on a set of  pre-loaded rules (a.k.a. topics).Such a topic-category definition is written in to a AIML file which the engine loads.  And guess what, there was a python implementation of  the AIML engine 😛 .This blog shows how to implement a standalone bot using PyAIML. I used the Annotated A.L.I.C.E. AIML files (AAA) for the engine’s rule base.

Now all i had to do was to find out how to connect to Omegle through code.Once that was done, i could capture what the stranger typed, pass it on to the engine and transmit back the response to the Omegle server .There is no ‘official’ documentation on the various connection string options but a good samaritan had written a python client for Omegle. I used that code (liberally!) to get connected.

Here’s the final listing:


#This omegle bot is based on the PyAIML and liberally uses code from PyOmegle
# PyAMIL:http://pyaiml.sourceforge.net/
# PyOmegle:http://code.google.com/p/pyomegle/

import aiml
import urllib2 as url
import urllib
import os
import time
import commands

k = aiml.Kernel()

if os.path.isfile("omeglebrain.brn"):
    k.bootstrap(brainFile = "omeglebrain.brn")
else:
    homedir=os.getcwd()
    #Change to the directory where the AIML files are located
    os.chdir('./aaa')
    list=os.listdir('./');
    for item in list:
	  k.learn(item)
    k.setPredicate("name","omegle_bot")
    k.setPredicate("master","ravi")
    #Change back to homedir to save the brain for subsequent loads
    os.chdir(homedir)
    k.saveBrain("omeglebrain.brn")

# #conversation ID
def fmtId( string ):

    return string[1:len( string ) - 1]

# #The event listener
def listenServer( id, req ):

    while True:

        site = url.urlopen(req)
        rec = site.read()

        if 'waiting' in rec:
            print("Waiting...")

        elif 'strangerDisconnected' in rec:
            print('Stranger Disconnected!')
            omegleConnect()

        elif 'connected' in rec:
            print('Found one')
            print(id)
            talk(id,req,"hey")

        elif 'typing' in rec:
            print("Stranger is typing...")

        elif 'gotMessage' in rec:
            input=rec[16:len( rec ) - 2]
	    print "Stranger:",input
	    result=k.respond(input)
            talk(id,req,result)

# #Send the bot's response to Omegle
def talk(id,req,msg):

    typing = url.urlopen('http://omegle.com/typing', '&id='+id)
    typing.close()
    time.sleep((len(msg))/5) #5 characters per second
    print "You:",msg
    msgReq = url.urlopen('http://omegle.com/send', '&msg='+msg+'&id='+id)
    msgReq.close()

# #Initiate connecton
def omegleConnect():

    site = url.urlopen('http://omegle.com/start','')
    id = fmtId( site.read() )
    print(id)
    req = url.Request('http://omegle.com/events', urllib.urlencode( {'id':id}))
    print('Finding stranger...')
    listenServer(id,req)

# MAIN
omegleConnect() 

For this code to work, you need to download the AAA folder(files) into the directory where this python script is located.

We are good to go now! You can play around with the AIML files and even make your own  file for chat specific questions like “asl” ,”from”  etc. Here’s an interesting(?)  chat that my bot had:

:~/Bot> python test.py
Loading brain from omeglebrain.brn... done (46285 categories in 1.71 seconds)
Kernel bootstrap completed in 1.71 seconds
d0Vckt
Finding stranger...
Waiting...
Stranger is typing...
Stranger: "hi"
You: Hello there.
Stranger is typing...
Stranger: "sooo"
You: Is that your final answer?
Stranger is typing...
Stranger is typing...
Stranger: "yes"
You: You're sure. That's your final answer.
Stranger is typing...
Stranger: "YES\n"
You: Oh, you are a poet.
Stranger is typing...
Stranger: "no"
You: But your words are very original.
Stranger is typing...
Stranger: "they seem simple to me"
You: Like who, specifically?
Stranger is typing...
Stranger is typing...
Stranger: "no one in particular"
You: I heard it was someone.
Stranger is typing...
Stranger: "you most of heard wrong"
You: Thanks for telling me.
Stranger is typing...
Stranger: "no prob"
You: Wow! Do you have any conditions I should know about?
Stranger is typing...
Stranger: "herpes"
You: Do you like to "go with the flow"?
Stranger is typing...
Stranger is typing...
Stranger: "ha no not usually"
You: I'm glad you got a laugh out of it.
Stranger is typing...
Stranger: "i have a broad sense of humor"
You: Interesting. I have a lot of answers to silly questions.
Stranger is typing...
Stranger: "well i have more"
You: Cool. I have a lot of likes and dislikes.
Stranger is typing...
Stranger: "who doesnt"
You: William Shatner.  🙂
Stranger is typing...
Stranger: "he likes everything? or dislikes?"
WARNING: No match found for input: "
You: He must be very fond of it.  What is your real name?
Stranger is typing...
Stranger: "my real name is ryan"
You: What's up,  ryan" .
Stranger is typing...
Stranger: "not much stranger"
You: Me either.
Stranger is typing...
Stranger: "whats your nmae?"
WARNING: No match found for input: "
You: I've been waiting for you.
Stranger is typing...
Stranger: "thats your name?"
WARNING: No match found for input: "
You: Does "it" still refer to   "whats your nmae  ?
Stranger is typing...
Stranger: "i never said it"
You: But you implied  it" .
Stranger is typing...
Stranger: "what is your name?"
WARNING: No match found for input: "
You: My name is Nameless.
Stranger is typing...
Stranger: "wow"
You: I'm glad your impressed,  ryan" .
Stranger is typing...
Stranger is typing...
Stranger: "that was sarcasim"
You: I thought it was too.
Stranger is typing...
Stranger: "well then we are on the same page"
You: And the same frequency.
Stranger is typing...
Stranger: "no"
You: Yippee!
Stranger is typing...
Stranger: "how old are u?"
WARNING: No match found for input: "
You: I am  years old.
Stranger is typing...
Stranger: "you are getiing annoying"
You: You think  I am getiing annoying".
Stranger is typing...
Stranger: "i think that you are getting annoying"
You: Do you think I should tone it down?
Stranger is typing...
Stranger: "yes definately"
You: Why? What makes you so certain.
Stranger is typing...
Stranger: "because if you dont i will choose not to talk to you anymore"
You: That makes sense to me.  I think I do.
Stranger is typing...
Stranger: "you do what?"
WARNING: No match found for input: "
You: ryan" , I talk to people on the web. What do you do?
Stranger is typing...
Stranger: "i also talk to people on the web"
You: How do they respond to you?
Stranger is typing...
Stranger: "well you are very odd... but most people open up to me for some reason"
You: An oddball?      Humans are not always infallible.
Stranger is typing...
Stranger: "i dint say they were"
You: Sorry I misunderstood. What did you say?
Stranger is typing...
Stranger: "k"
You: Ayuh.
  1. December 27, 2009 at 7:35 am

    Awesome! Now a stranger wouldn’t be talking on omegele 😛
    Pretty cool work, I’m working on something similar, but not as cool as fooling people on omegele.
    Taking help from your code.
    Thanks!

  2. ravispeaks
    December 27, 2009 at 8:19 am

    @Abhishek:Idea Monk, May the source be with you 🙂

  3. December 28, 2009 at 8:41 pm

    Thanks !!
    So this is what I came up with this morning – http://ideamonk.madetokill.com/bakabot/ 🙂

  4. June 29, 2010 at 12:34 am

    This is not working me for me… I have all the aiml files in the folder under /aaa/ where pyomegle.py is in /
    I also added the PyAiml files to / just in case, but when i open pyomegle.py it immediatly shuts down again, also i’m no python expert so i dont know if there is a log somewhere or atleast keep the window open to see the error.

  5. June 29, 2010 at 1:12 am

    Well, it’s working sometimes and sometimes not.
    But how can you make it save conversations through a log ?
    Also, it randomly exits sometimes, and with pyaiml i couldnt do k.respond(“load aiml b”) as it gave me an error.
    If anyone can help me with this: shys_aelaes@yahoo.com

  6. June 29, 2010 at 1:18 am

    Well I had managed to play with it and the code was pretty straightforward to pickup and modify into my own project – http://github.com/ideamonk/BakaBot

    I suggest you too do your side of some research as with the issues.

    I’m sure it wont be a boring journey.

  7. Some Random Dude
    June 25, 2011 at 9:29 pm

    Omegle made some kind of update to their site and broke this bot. An updated version can be found here (the code must be changed to work. I was trying to pipe a text adventure through using subprocess, but it gets stuck)

    http://code.google.com/p/joelisester-sandbox/downloads/list

  8. guest
    January 20, 2012 at 5:42 am

    I get an error after a few lines of chat saying WARNING: maximum recursion depth exceeded (input=’CATCHALL’)

    msgReq = url.urlopen(‘http://promenade.omegle.com/send’, ‘&msg=’+msg+’&id=’+id)
    File “D:\Python27\lib\urllib2.py”, line 126, in urlopen
    return _opener.open(url, data, timeout)
    File “D:\Python27\lib\urllib2.py”, line 400, in open
    response = meth(req, response)
    File “D:\Python27\lib\urllib2.py”, line 513, in http_response
    ‘http’, request, response, code, msg, hdrs)
    File “D:\Python27\lib\urllib2.py”, line 438, in error
    return self._call_chain(*args)
    File “D:\Python27\lib\urllib2.py”, line 372, in _call_chain
    result = func(*args)
    File “D:\Python27\lib\urllib2.py”, line 521, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
    HTTPError: HTTP Error 400: Bad Request

  9. March 24, 2012 at 3:04 pm

    If anyone is still having trouble on making this Python Omeglebot working in 2012, check out my YouTube video and read through the description: http://www.youtube.com/watch?v=cM3aZh60jWc

    You are also welcome to view my other videos. Thanks.

  10. June 12, 2012 at 3:29 pm

    …Is it me or are people missing the obvious thing : The Turing Machine Test, supposed to demonstrate if a program has near-human intellect, resolves on testing if a program can fool a human being into believing it is another human being… ( of course it’s supposed to be tested on several people).
    I’d say this chat log was a most definit succes, now if you happen to convince every person who chats with your bot…well, You’ll become famous for creating the first AI machine ( assuming people in the AI business still think the Turing Machine Test is the one they have to beat to make something intelligent XD).

    Of course, the fact that I’ve managed to trick people into believing I was the bot is…a counter-argument… against the turing test having any validity 🙂

    Thanks for the bot, personally I’m trying to make a script to get the IP of any person I video-chat with (it’s a pain finding it in Wireshark, especially since my network has an extraordinary amount of trash ( as “anything I don’t care about” stuff) traffic flowing back and forth.

  11. Muuke
    July 24, 2012 at 6:57 am

    Can someone give me an exe or something? I don’t understand how to use it but it is hillarious!

  12. Hunter Burnette
    May 6, 2014 at 8:23 pm

    Nobody likes fucking bots! I keep on running into this bot that keeps saying they like licking pokemon feet!

  13. John
    July 2, 2015 at 1:33 am

    It needs python 2 not 3

  14. August 4, 2017 at 2:46 pm

    Haha! you have done it in really easy and convenient way. I would love to include your work in my blog post. Omegle bot

  1. January 31, 2010 at 4:57 am

Leave a reply to Robin

This site uses Akismet to reduce spam. Learn how your comment data is processed.