Hosting & Domaining Forum

Hosting Discussion => Hosting Software and Control Panels => Topic started by: naizsmile on Feb 09, 2023, 09:48 AM

Title: Two PHP telegram bots on the same webhosting
Post by: naizsmile on Feb 09, 2023, 09:48 AM
Hi there. A telegram bot that operates via Webhook exists, and I've encountered some issues with it.

When I run the bot from the root directory of the site, it works fine. However, when I create an additional folder and access the file on the hosting index.php with the path primer.com/folder/index.php, the bot stops working. Interestingly, if I put the main file in primer.com/index.php, the bot functions again.

I'm wondering if there is a way to host two bots on the same website and hosting service?
Title: Re: Two PHP telegram bots on the same hosting
Post by: sujitbikash on Feb 09, 2023, 10:38 AM
There seem to be two potential solutions to the bot deployment issue.

The first is to properly inform the bot of where it should operate. However, it's unclear whether or not this is a feasible option.

Alternatively, one could use a VPS to host their own web server and configure up to 100 bots or more.

In terms of additional thoughts on this topic, while using a VPS may require more technical expertise, it can provide greater control and flexibility for bot deployment. It may also be beneficial for larger-scale operations that require multiple bots running simultaneously. However, for smaller businesses or individuals, utilizing existing hosting services and consulting with technical support may be a more practical choice.
Title: Re: Two PHP telegram bots on the same hosting
Post by: ZoriWser on Feb 09, 2023, 11:26 AM
Deploying a bot to different directories or even different websites is not a difficult task.

However, if the bot fails to operate when placed in a directory, it could indicate that the bot has been poorly written. A properly designed bot should be able to automatically determine its directory and function accordingly.

 it's worth noting that while setting up a bot may seem like a straightforward task, it still requires attention to detail and appropriate programming knowledge. Additionally, keeping the bot up-to-date and monitoring its performance can help ensure that it functions optimally.
Title: Re: Two PHP telegram bots on the same webhosting
Post by: Novel Web Solution on Jul 20, 2024, 01:15 AM
Let's explore the challenges you're facing with your Telegram bot in detail and how to successfully host multiple bots on the same website.

1. Webhook Configuration:
After moving your bot to a new directory, you must update the webhook URL that Telegram uses to send updates to your bot. The webhook URL should reflect the new location of your bot's code. Initially, you may have set a webhook URL like this:

https://api.telegram.org/bot<YOUR_TOKEN>/setWebhook?url=https://primer.com/index.php

After shifting the bot to a subfolder, you need to modify the URL accordingly:

https://api.telegram.org/bot<YOUR_TOKEN>/setWebhook?url=https://primer.com/folder/index.php

Use a web browser or a tool like Postman to run the command, ensuring to replace <YOUR_TOKEN> with your actual bot token.

2. File Permissions:
Check that the new directory and index.php file have the correct permissions set. Typically, you would want the directory to have a permission setting of 755 and the file to have 644. You can adjust these permissions using an FTP client or via command line if you have access.

Here's what those permissions imply:
- 755: The owner can read, write, and execute; the group and public can read and execute.
- 644: The owner can read and write; the group and public can read.

3. Server Configuration:
If you are using Apache as your web server, verify whether there is an .htaccess file in your root directory or the new folder. The .htaccess file can change default behaviors and may cause routing problems. Ensure there are no conflicting rules that could affect how requests are processed for your bot.

If using Nginx, examine your server block configuration to ensure requests to the folder are being allowed without restriction.

4. Error Logs:
Continuously monitor your web server error logs. These logs provide vital insights into what might be going wrong. Typically, you can find them in the following locations based on your server setup:
- For Apache: Usually located in /var/log/apache2/error.log or /var/log/httpd/error_log.
- For Nginx: Generally found in /var/log/nginx/error.log.

Reviewing these logs when accessing the webhook will help identify issues like file not found errors or permission denied errors.

5. Namespace Issues:
If your bot employs any frameworks, such as Laravel or Symfony, it's essential to understand how routing and namespaces work within those frameworks. Moving files can inadvertently change how routes are recognized, so ensure that routing configurations reflect the new paths.

6. Testing the Bot:
Once you have updated the webhook and verified permissions, conduct thorough testing. Send a message to your bot or utilize another Telegram API method to see how it responds. Any errors encountered should be logged on your server, aiding in further troubleshooting.

7. Hosting Multiple Bots:
To host multiple bots without conflicts, consider structuring your directories like this:

- primer.com/bot1/index.php
- primer.com/bot2/index.php

Each bot will have its own directory, and you will need to set webhooks for each one separately:

- For bot1: Set the webhook to https://primer.com/bot1/index.php
- For bot2: Set the webhook to https://primer.com/bot2/index.php

If you wish to use subdomains for better organization and to minimize conflicts, the structure could be:

- bot1.primer.com
- bot2.primer.com

In this case, you must create DNS records to point these subdomains to your hosting server and ensure the web server is configured properly to serve the right content for each subdomain.
Make sure the webhook URL matches the location of your bot, verify file permissions, examine server configurations and logs, and conduct testing to ensure everything operates as intended. By following these steps, you can effectively run multiple bots on the same hosting environment.
Title: Re: Two PHP telegram bots on the same webhosting
Post by: Annermol on Feb 12, 2025, 02:04 AM
The fact that your Telegram bot works in the root directory but not in a subfolder suggests that the webhook URL is likely configured to point to the root.

When you move the bot to a subfolder, the Telegram API still tries to reach the original URL, leading to a failure in communication. To host two bots on the same domain, ensure each bot has its own unique webhook URL. Update the webhook for the second bot to point to primer.com/folder/index.php.