Skip to content

JokeBot is a simple Telegram bot that sends random jokes or jokes containing specific words provided by the user.

License

Notifications You must be signed in to change notification settings

MehdiSlr/JokeBots_Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JokeBot

JokeBot is a simple Telegram bot designed to send jokes to users based on various categories or specific words. The bot uses the JokeAPI to fetch jokes and interacts with users through the Telegram API.

Features

  • Send random jokes from multiple categories.
  • Send jokes containing specific words provided by the user.
  • Language selection feature to support multilingual user interactions.
  • Provides bot information and usage instructions.
  • Logs interactions for debugging and improvement.

Requirements

  • PHP 7.4 or higher
  • cURL extension for PHP
  • A Telegram bot token
  • MySQL or compatible database

Installation

Follow these steps to set up the bot:

  1. Clone the repository

Clone the repository to your local machine and navigate into the project directory:

git clone https://github.com/MehdiSlr/JokeBots_Bot.git
cd JokeBots_Bot
  1. Install Dependencies

There are no specific PHP dependencies to install via Composer at the moment, but ensure you have the cURL extension enabled.

  1. Configure config.php

Create a config.php file in the project root directory with your Telegram bot token and database details:

<?php
$token = 'YOUR_TELEGRAM_BOT_TOKEN';
$conn = mysqli_connect('YOUR_DATABASE_HOST', 'YOUR_DATABASE_USERNAME', 'YOUR_DATABASE_PASSWORD', 'YOUR_DATABASE_NAME');
?>
  1. Set the Bot Webhook

Set the webhook URL for the bot by entering the following URL in your browser:

https://api.telegram.org/bot<YOUR_TELEGRAM_BOT_TOKEN>/setWebhook?url=<YOUR_HOST_URL>/index.php
  1. Update the Database Schema

Ensure that your database has the necessary tables for the bot. Here’s an example SQL schema to set up the users and update_log tables:

CREATE TABLE `users` (
    `uid` BIGINT PRIMARY KEY,
    `name` VARCHAR(255),
    `user` VARCHAR(255),
    `type` VARCHAR(255),
    `cat` VARCHAR(255),
    `lang` VARCHAR(5)
);

CREATE TABLE `update_log` (
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `json` TEXT
);
  1. Start the Bot

Start a conversation with the bot on Telegram to initiate interaction.

Usage

Sending Messages

The msg function is used to send messages to the Telegram bot. It takes two parameters: the API method and the parameters for the method.

msg('sendMessage', [
    'chat_id' => $chat_id,
    'text' => $message,
]);

Fetching Jokes

The Joke function is used to fetch a joke from the JokeAPI based on a category and a search term.

$joke = Joke('Programming', 'bug');

Formatting Jokes

The JokeMsg function is used to format a joke message with its category.

$formatted_joke = JokeMsg('Programming', 'Why do programmers prefer dark mode?');

Predefined Text Messages

The text function is used to retrieve predefined text messages for the bot.

$welcome_message = text('welcome');

Keyboard Layout

The keyboard function is used to generate the appropriate keyboard layout for the bot.

$keyboard = keyboard('home');

Bot Commands and Callbacks

The bot responds to commands and callback queries:

  • /start - Displays the welcome message and main keyboard.
  • Change Category | 🔄️ - Switches to custom joke mode.
  • random - Sends a random joke.
  • custom - Sends a joke containing the search term provided by the user.
  • language - Allows users to select a language preference.
  • info - Displays the bot and API information.
  • Callback queries for joke categories (Any, Dark, Pun, Miscellaneous, Programming, Spooky, Christmas).

Database Logging

The bot logs incoming updates to the update_log table for debugging purposes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

Support

If you have any questions or feedback, please open an issue on GitHub.

Author

Created by Mehdi Salari - Telegram @Meytttii.

About

JokeBot is a simple Telegram bot that sends random jokes or jokes containing specific words provided by the user.

Topics

Resources

License

Stars

Watchers

Forks

Languages