Building an AI-Powered Social Media Intern for Ethnic Restaurants

August 26, 2024

Maintaining a compelling social media presence is crucial for restaurants aiming to attract and retain customers. While many small business owners excel at traditional local marketing, adapting these strategies to the digital realm presents new challenges. Restaurant owners are experts in crafting delicious food, creating a welcoming ambiance, and running efficient operations; however, navigating the complexities of digital marketing—such as trending hashtags, geo-tags, and content targeting—can be daunting. This is especially true for ethnic restaurants that wish to share their authentic dishes but struggle with consistent and effective online engagement.

The Challenge for Ethnic Restaurants

Ethnic restaurants, like those specializing in Chettinad cuisine, often face unique hurdles in the digital space. They want to showcase their rich culinary heritage and maintain control over their brand identity but may lack the resources or expertise to do so effectively. Many rely on external agencies to manage their social media accounts, which can cost anywhere from $300 to $1,500 per month. This not only adds a financial burden but also creates a disconnect between the restaurant's authentic voice and the content being shared.

Introducing an AI-Powered Solution

To address these challenges, we developed an AI-powered "social media intern" using the OpenAI API. This solution automates the creation of Instagram captions and hashtags from food images shared via Telegram. By streamlining the process, restaurants can produce consistent, high-quality social media content without the need for complex web dashboards or expensive third-party services.

Benefits of the AI-Powered System

  • Cost Reduction: Eliminates the need for costly social media agencies.
  • Authentic Content: Ensures the restaurant's unique voice and brand identity are preserved.
  • Ease of Use: Integrates with familiar messaging platforms, making it accessible for staff.
  • Time Efficiency: Automates repetitive tasks, allowing staff to focus on service delivery.
  • Improved Engagement: Consistent posting with engaging content boosts online visibility.

Building the Application: A Step-by-Step Guide

This guide details how to build an application that:

  • Reminds staff to take daily pictures.
  • Receives food images from a Telegram chat.
  • Generates Instagram captions and hashtags using OpenAI's language models.
  • Allows the restaurant team to review and approve content.
  • Automatically posts approved content to Instagram.

1. Setting Up Reminders for Daily Photos

Implement a notification system to remind staff to take and send pictures of dishes. This can be done by scheduling messages through the Telegram bot or using third-party scheduling tools.

2. Receiving Images via Telegram

Why Choose Telegram?

  • Developer-Friendly: Telegram offers a robust API that's easy to work with.
  • Familiar Interface: Many small business owners are accustomed to messaging apps.
  • Ease of Integration: Supports bots and automated workflows without extensive setup.

Steps to Set Up a Telegram Bot

  • Create a Bot:
    • Use BotFather on Telegram to create a new bot.
    • Obtain the API token provided upon creation.
  • Configure Permissions:
    • Add the bot to the desired group chat or channel.
    • Grant necessary permissions, such as reading messages and accessing media.

Implementing Image Handling

  • Webhook Setup:
    • Set up a webhook URL where Telegram will send updates.
    • Use services like ngrok for local development or host on a server.
  • Notification System:
    • Program the bot to send reminders and confirm receipt of images.
    • Notify the team when new content is ready for review.
  • Download Images:
    • Use the Telegram Bot API's getFile method to download images.
    • Store images securely for processing.
  • Editing and Approval Interface:
    • Implement commands like /approve, /edit, /refresh, and /cancel.
    • Allow staff to interact with the bot for content management.
  • Database Storage:
    • Use a database to store images, captions, hashtags, and approval status.
    • Options include SQLite for simplicity or PostgreSQL/MySQL for scalability.

3. Generating Captions and Hashtags with OpenAI's API

First, we need to extract features from the image to provide context to the language model. Use OpenAI's Multimodal Models that easily processes the image with a few different prompting techniques. Basic prompts like “Create an engaging Instagram caption for a restaurant featuring the following dish. Include appropriate hashtags.” were good for early iterations. Through trial and error we identified that a combination of multi-modal and persona-based prompting worked better than contextual and few-shot prompting with the gpt-4o model.

Generating Captions and Hashtags

  • Constructing the Prompt: Create a prompt that includes the dish description and desired tone. Example:
Create an engaging Instagram caption for the following Chettinad dish: [Dish Name/Description]. Use a friendly tone and include relevant hashtags.
  • Persona-Based Prompting: Specify the restaurant's voice and style. Example:
As the voice of [Restaurant Name], write a warm and inviting Instagram caption for our special dish, [Dish Name]. Highlight its unique flavors and include hashtags like #ChettinadCuisine and #AuthenticIndianFood.
  • API Integration:
    • Use OpenAI's API to send the prompt and receive the generated caption.
    • Implement error handling to manage API response issues. Example Code Snippet
import openai

openai.api_key = 'YOUR_OPENAI_API_KEY'

def generate_caption(dish_description):
    prompt = f"Create an engaging Instagram caption for the following Chettinad dish: {dish_description}. Use a friendly tone and include relevant hashtags."
    response = openai.Completion.create(
        engine='text-davinci-003',
        prompt=prompt,
        max_tokens=150
    )
    caption = response.choices[0].text.strip()
    return caption

4. Implementing the Review and Approval Interface

Telegram Bot Interaction

  • Preview Generated Content:
    • Send the generated caption and image back to the Telegram chat.
    • Allow staff to review and make changes if necessary.
  • Approval Commands:
    • /approve: Confirms the content is ready to post.
    • /edit: Lets staff manually edit the caption or hashtags.
    • /refresh: Generates a new caption.
    • /cancel: Discards the current content.

Updating the Database

  • Record the approval status and any edits made.
  • Use this data to improve future content and for record-keeping.

5. Automating Posting to Instagram

Understanding the Instagram Graph API

Automated posting requires integration with the Instagram Graph API and a connected Facebook app.

Prerequisites

  • Instagram Business Account:
    • Convert your account to a business profile in the Instagram app settings.
  • Facebook App Setup:
    • Create an app in the Facebook for Developers portal.
    • Link your Instagram Business account to the Facebook app.
  • Access Tokens and Permissions:
    • Obtain an access token with the necessary permissions (instagram_basic, instagram_content_publish).
    • Use Facebook's Graph API Explorer for testing.
    • Implementing the Posting Functionality
  • Authenticate Requests:
    • Use the access token to authenticate API calls.
  • Upload the Image:
    • Use the /media endpoint to upload the image.
    • Provide the image URL or upload it directly.
  • Create the Media Object:
    • Include the caption generated by OpenAI.
  • Publish the Content:
    • Use the /media_publish endpoint to publish the media object to your feed. Example Code Snippet
import requests

access_token = 'YOUR_INSTAGRAM_ACCESS_TOKEN'
instagram_account_id = 'YOUR_INSTAGRAM_ACCOUNT_ID'

def publish_to_instagram(image_url, caption):
    # Step 1: Upload the image
    media_url = f'https://graph.facebook.com/v15.0/{instagram_account_id}/media'
    media_params = {
        'image_url': image_url,
        'caption': caption,
        'access_token': access_token
    }
    media_response = requests.post(media_url, data=media_params)
    media_id = media_response.json().get('id')

    # Step 2: Publish the image
    publish_url = f'https://graph.facebook.com/v15.0/{instagram_account_id}/media_publish'
    publish_params = {
        'creation_id': media_id,
        'access_token': access_token
    }
    publish_response = requests.post(publish_url, data=publish_params)
    return publish_response.json()

Notes

  • Token Refresh: Implement a system to refresh tokens as they expire. Consider using long-lived tokens for convenience.
  • Error Handling: Handle exceptions and API errors gracefully.

Adding Location and Music

  • Location Tags:
    • Include location_id in your media upload parameters.
    • Obtain location_id via the Facebook Graph API.
  • Music Integration:
    • As of now, adding music via the API is not supported.
    • Monitor API updates for this feature.

Challenges and Considerations

Image Recognition Limitations

  • Complex Dishes:

    • Ethnic dishes may not be recognized accurately by image recognition APIs.
    • Solution: Encourage staff to provide brief descriptions with images.
  • Image Quality:

    • Poor-quality images can affect caption relevance.
    • Solution: Train staff on basic photography skills.

OpenAI API Usage

  • Cost Management:

    • Monitor usage to prevent unexpected charges.
    • Use the OpenAI dashboard for tracking.
  • Content Filtering:

    • Implement safety checks to filter out inappropriate content.
    • Use OpenAI's content filtering guidelines for reference.

Compliance and Permissions

  • User Privacy:

    • Ensure compliance with GDPR and other privacy laws.
    • Avoid storing personal data unnecessarily.
  • Platform Policies:

    • Adhere to Telegram's and Instagram's terms of service.
    • Regularly review policies to stay compliant.

Access Tokens and Security

  • Secure Storage:

    • Store API keys and tokens in environment variables or use secret management tools.
    • Avoid hardcoding sensitive information.
  • Token Refresh Mechanisms:

    • Implement automated token refresh procedures.
    • Monitor token expiration dates.

Next Step is to turn the automated application into an agent performing the tasks.

Conclusion

Automating social media content creation using AI can significantly benefit ethnic restaurants by reducing workload and ensuring consistent, engaging posts. By integrating familiar tools like Telegram with powerful AI language models and social media platforms, restaurants can maintain control over their brand identity and connect more effectively with their audience. This approach not only saves time and money but also empowers restaurant teams to share their authentic culinary stories with the world.