Pinterest Stumbleupon Whatsapp
Ads by Google

how to make a chat botOne of the great things about owning a website and being an online writer is the opportunity to connect with so many people across the world.

Unfortunately, there is one difficulty with connecting with so many people across the world – time zones. You may want to be available to interact with your readership or to do business with potential clients, but at some point, you have to sleep.

Enter the chat bot. A chat bot can serve as your front desk digital secretary when you aren’t available to accept IM requests. The intelligence of this digital “secretary” really only comes down to how well you’re able to program the dialogue into your chat bot.

MUO has previously covered ChitterIM, which is essentially a chat bot that accepts IM commands from you in order to interact with Twitter. This is just one example of how a chat bot can automatically perform tasks for your site or your business, but in this article I’m going to show you the basic steps to make your own chat bot for your own site or business.

How to Make a Chat Bot

By far, the best available tool for doing this is IMified. We’ve briefly covered IMified in the directory, and Mark covered Turn Your IM Program Into A Productivity Tool Using Imified Turn Your IM Program Into A Productivity Tool Using Imified Read More how to use the prebuilt IMified bot to use a whole list of premade applications that the folks at IMified already offer.

However, you can also create your own customized chat bot by signing up for a new account, and then clicking on the “Create a New Bot” button on the right menu.

Ads by Google

how to make a chat bot

Setting up your own customized chat bot is as simple as creating an ID for your bot, and defining the URL where your bot’s chat code will reside. In my case, I’m storing the PHP code for the bot programming on my own website, so I’ve provided the path to that PHP file.

make a chat bot

When you’re done, you’ll receive a long “Bot Key” that you can use when you get more deeply into integrating your bot into various services, such as programming your own Twitter features. However, for now we’re going to focus on creating that basic PHP file where you can program your bot to interact with your users.

make a chat bot

To show how this basically works, I’m going to explain how the basic PHP file offered by IMified works. Here’s what the basic interaction code looks like.


You said " . $_REQUEST['value2'] . " that you know."; break;} } ?>

If you step through this sample code you’ll see just how simple it is. The IMified bot lets you take the conversation through several “steps”, and you can force navigation. You can allow the user to type something and continue to the next step by doing nothing and just ending that section with “break;”. If you end your echo with a “”, it’ll reset the bot (and the conversation) back to the start. Your bot will forget everything that was recently said.

IMified also lets you use a “goto” command to go to a specific step in the conversation, and will force the conversation one step back (I’ll show you how this works below).

But first, here’s what the bot conversation will look like. The bot is called “tswdesk”.

make a chat bot

Of course, you’re going to want your chat bot to be a little more intelligent (and interesting) than this simple example. However, since you are controlling the conversation using PHP code, just think of the possibilities. Based on the conversation, you could perform different services for your readers or your clients. Send out an email, log “feedback” test to a file, or provide the user with requested information. The possibilities are really unlimited.

Here’s a sample PHP bot code where you can provide the visitor with the option to select from a menu of “services” that your bot offers.


1-Subscribe to newsletter
2-Request to talk to editor
3-Submit Feedback
4-Subscribe to RSS Feed
5-Request a phone call

Please type your request:"; break; } else { echo "I don't understand your answer, try again. "; break; } } case 3: { if ($_REQUEST['msg'] == "1") {echo "Thank you. I've subscribed you to our newsletter using your IM email account. Have a nice day.";} if ($_REQUEST['msg'] == "2") {echo "Thank you. I've let our editor know that you would like to speak with him. Have a nice day.";} if ($_REQUEST['msg'] == "3") {echo "Thank you. Please type your feedback now.";} if ($_REQUEST['msg'] == "4") {echo "Thank you. Add our RSS url to your Reader to subscribe: http://www.topsecretwriters.com/rss. Have a nice day.";} if ($_REQUEST['msg'] == "5") {echo "Thank you. You've requested a phone call. Please type your phone number.";} break; } case 4: { echo "Thank you. Your information has been submitted. Have a nice day."; break; } } ?>

Now that there’s a bit more logic and information in the background code, you can see how much more intelligent the bot will appear to users, as shown in the conversation below.

how to make a chat bot

Now, carrying out some of these tasks may be as simple as writing to a logfile or sending out an email to the editor using PHP, but if you want to have your bot serve you by accepting Twitter commands or issuing alerts to all chat “friends”, it will require using some of the IMified APIs. That’s outside the scope of this article, but we’ll get to those cool features in an upcoming article.

Have you ever used IMified to customize your own bot, or have you used any other similar service? Share your chat bot experiences and insights in the comments section below.

Image Credit: Shutterstock

  1. mauro
    April 26, 2016 at 1:07 am

    i'm looking for an automated chat, that just posts comments at a certain time into a chat. i don't need it to create the posts itself as they are already in a script. any ideas? thank you

  2. Php Power
    October 19, 2015 at 3:13 pm

    http://codecanyon.net/item/php-smart-robot-chat-support/13199679?ref=phppowerarts

    this idea implemented here :) , very smart robot chat support and you can learn him :)

  3. Vic Duan
    May 24, 2012 at 10:43 am

    That's interesting. However it might be painful to maintain a chat bot with PHP as the number of responses increase. Here is a chat bot that is more powerful, yet simple & easy to use - it doesn't require coding at all - http://acobot.com.

  4. Ryan Dube
    February 10, 2012 at 12:45 am

    Sorry guys, I'll get the code boxes fixed up.

  5. SthevetotheH
    February 4, 2012 at 4:41 am

    I like it, I think robots are great. Next step, online assassin for 99cent.

  6. Harroman
    February 2, 2012 at 11:25 pm

    There are 2 long boxes but the code is missing, please can we get the code from somewhere.
    Thanks

    • Ryan Dube
      February 10, 2012 at 12:55 am

      Fixed - sorry about that, it must have gotten stripped during the editing process.

  7. Stephen Rice
    February 2, 2012 at 8:32 pm

    You should be absolutely up front about it if you ever make your customers talk to a bot. The TSWDesk example is very good for that reason.

  8. Umesh
    February 2, 2012 at 7:37 pm

    Hey can you share PHP Code

    • Ryan Dube
      February 10, 2012 at 12:56 am

      I've fixed the article to reflect the code, sorry about the error!

Leave a Reply

Your email address will not be published. Required fields are marked *