Yelp is making its AI chatbot way more useful
Back to Tutorials
techTutorial

Yelp is making its AI chatbot way more useful

April 21, 20261 views5 min read

Learn to build a basic AI chatbot assistant similar to Yelp's digital concierge that can help users find local businesses and get directions.

Introduction

\n

In this tutorial, you'll learn how to create a simple AI chatbot assistant similar to the one Yelp is developing. We'll build a basic conversational interface that can help users find local businesses, get directions, and perform other useful tasks. This tutorial will teach you fundamental concepts of AI chatbots using Python and open-source tools, giving you a practical understanding of how digital concierges work.

\n\n

Prerequisites

\n

To follow this tutorial, you'll need:

\n
    \n
  • A computer with internet access
  • \n
  • Python 3.7 or higher installed
  • \n
  • Basic understanding of Python programming concepts
  • \n
  • Some familiarity with command-line tools
  • \n
\n\n

Step-by-Step Instructions

\n\n

Step 1: Set Up Your Development Environment

\n

Install Required Python Packages

\n

First, we need to install the necessary Python packages for our chatbot. Open your terminal or command prompt and run:

\n
pip install python-telegram-bot nltk
\n

This installs the Telegram bot library and Natural Language Toolkit (NLTK), which will help us understand user requests.

\n\n

Step 2: Create Your Basic Chatbot Structure

\n

Initialize the Main Bot Class

\n

Create a new Python file called chatbot.py and start with this basic structure:

\n
import nltk\nfrom telegram import Update\nfrom telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes\n\n# Download required NLTK data\nnltk.download('punkt')\n\n# Your bot's token (you'll get this from BotFather on Telegram)\nBOT_TOKEN = 'YOUR_BOT_TOKEN_HERE'\n\n# Simple business database\nbusinesses = {\n    'pizza': ['Pizza Palace', 'Tony\'s Pizza', 'Mamma Mia\'s'],\n    'coffee': ['Starbucks', 'Dunkin\'', 'Local Coffee Co'],\n    'restaurant': ['The Golden Fork', 'Bistro Central', 'Tasty Bites']\n}\n\nasync def start(update: Update, context: ContextTypes.DEFAULT_TYPE):\n    await update.message.reply_text('Hello! I\'m your local assistant. Ask me about restaurants, coffee shops, or anything else!')\n\nasync def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE):\n    user_message = update.message.text.lower()\n    response = generate_response(user_message)\n    await update.message.reply_text(response)\n\ndef generate_response(message):\n    # Simple response logic\n    if 'pizza' in message:\n        return f'I found these pizza places: {\" and \".join(businesses[\"pizza\"])}'\n    elif 'coffee' in message:\n        return f'Here are some coffee shops: {\" and \".join(businesses[\"coffee\"])}'\n    elif 'restaurant' in message:\n        return f'Some restaurants I know about: {\" and \".join(businesses[\"restaurant\"])}'\n    else:\n        return 'I can help you find local businesses! Try asking about pizza, coffee, or restaurants.'\n\nasync def main():\n    # Create the Application and pass it your bot's token\n    application = Application.builder().token(BOT_TOKEN).build()\n\n    # Register command handlers\n    application.add_handler(CommandHandler(\"start\", start))\n    application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))\n\n    # Run the bot until the user presses Ctrl-C\n    await application.run_polling()\n\nif __name__ == '__main__':\n    import asyncio\n    asyncio.run(main())
\n\n

Step 3: Get Your Telegram Bot Token

\n

Register Your Bot with Telegram

\n

To test your chatbot, you'll need a Telegram bot token:

\n
    \n
  1. Open Telegram and search for @BotFather
  2. \n
  3. Start a chat with BotFather
  4. \n
  5. Type /newbot and follow the prompts
  6. \n
  7. Give your bot a name and username
  8. \n
  9. Copy the token that BotFather provides
  10. \n
\n

Replace YOUR_BOT_TOKEN_HERE in your code with the actual token you received.

\n\n

Step 4: Run Your Chatbot

\n

Test Your Local Assistant

\n

Save your Python file and run it in the terminal:

\n
python chatbot.py
\n

Your bot should now be running and waiting for messages. Open Telegram, find your bot by username, and start chatting!

\n\n

Step 5: Enhance Natural Language Understanding

\n

Improve Response Accuracy

\n

Let's make your bot smarter by using NLTK for better text processing:

\n
import nltk\nfrom nltk.tokenize import word_tokenize\nfrom nltk.corpus import stopwords\n\n# Add this to your imports\nnltk.download('stopwords')\n\n# Replace your generate_response function with this enhanced version\n\ndef generate_response(message):\n    # Tokenize the message\n    tokens = word_tokenize(message)\n    \n    # Remove stopwords (common words like 'the', 'is', 'a')\n    stop_words = set(stopwords.words('english'))\n    filtered_tokens = [word for word in tokens if word.lower() not in stop_words]\n    \n    # Look for keywords\n    if any(word in filtered_tokens for word in ['pizza', 'pasta', 'italian']):\n        return f'I found these pizza places: {\" and \".join(businesses[\"pizza\"])}'\n    elif any(word in filtered_tokens for word in ['coffee', 'cafe', 'espresso']):\n        return f'Here are some coffee shops: {\" and \".join(businesses[\"coffee\"])}'\n    elif any(word in filtered_tokens for word in ['restaurant', 'food', 'eat', 'dinner']):\n        return f'Some restaurants I know about: {\" and \".join(businesses[\"restaurant\"])}'\n    else:\n        return 'I can help you find local businesses! Try asking about pizza, coffee, or restaurants.'\n
\n

This improvement helps your bot understand variations in how users might ask for information, making it more user-friendly.

\n\n

Step 6: Add More Features

\n

Expand Your Bot's Capabilities

\n

Enhance your bot by adding more business categories:

\n
# Add more businesses to your database\nbusinesses = {\n    'pizza': ['Pizza Palace', 'Tony\'s Pizza', 'Mamma Mia\'s'],\n    'coffee': ['Starbucks', 'Dunkin\'', 'Local Coffee Co'],\n    'restaurant': ['The Golden Fork', 'Bistro Central', 'Tasty Bites'],\n    'bakery': ['Sweet Dreams Bakery', 'Cupcake Corner', 'Morning Bread'],\n    'bar': ['The Blue Moon', 'Red Lion Pub', 'City Lounge']\n}\n\n# Update your response function to handle new categories\nif any(word in filtered_tokens for word in ['bakery', 'bread', 'cake', 'pastry']):\n    return f'Here are some bakeries: {\" and \".join(businesses[\"bakery\"])}'\nelif any(word in filtered_tokens for word in ['bar', 'pub', 'night', 'drink']):\n    return f'Some bars I know about: {\" and \".join(businesses[\"bar\"])}'\n
\n

This makes your chatbot more versatile and helpful for users with different needs.

\n\n

Step 7: Deploy and Test

\n

Make Your Chatbot Public

\n

While we've been testing locally, you can deploy your chatbot to platforms like Heroku or any cloud service. For a simple test, you can also:

\n
    \n
  • Keep it running locally on your computer
  • \n
  • Use a service like ngrok to expose your local server to the internet
  • \n
  • Test with friends and family to get feedback
  • \n
\n

This approach mirrors how Yelp's AI assistant works - it's designed to be practical and helpful for everyday tasks.

\n\n

Summary

\n

In this tutorial, you've learned how to build a basic AI chatbot assistant similar to Yelp's digital concierge. You've created a bot that can understand user requests, search through a local business database, and provide helpful responses. The key concepts covered include:

\n
    \n
  • Setting up a Telegram bot with Python
  • \n
  • Basic natural language processing with NLTK
  • \n
  • Creating a database of local businesses
  • \n
  • Building conversational response logic
  • \n
\n

This foundation gives you the skills to expand your chatbot with more features, better AI models, and integration with real business databases - exactly what Yelp is doing to make their AI assistant more useful for everyday users.

Source: The Verge AI

Related Articles