Custom commands

Basic Commands

Custom commands are a great way to personalize your bot. You can set predefined messages or even send media such as photos, videos, and files that your bot will reply with whenever given a certain word or phrase. This is very useful and may help you add an FAQ to your bot, testimonials, and more. If you have programming knowledge and skills, you'll be able to create even more complex commands!

To create a custom command, simply type /custom_commands in your bot's chat and select the "Add" option. This will prompt you to set a trigger phrase and a response message. You can even attach photos, videos, or files to your response to make it more engaging. With custom commands, you can personalize your bot to meet the specific needs of your audience.

Then, your bot will prompt you to enter a name for your new command. This name will be the trigger phrase that activates the message you create next.

After naming your custom command, you'll be prompted to enter the message that your bot will send to users when they type the command. This can be any type of content, including text, media, and files. You can also add multiple messages to your custom command to provide more than one response. Additionally, you can use captions to further personalize your messages.

After clicking the "Save" button, your custom command is ready to use! Users can trigger it by typing the name of the command you created. Don't forget to test your custom command and make sure it works as expected. You can always go back and edit or delete the custom command if needed by going to /custom_commands and selecting the appropriate option.

After creating a custom command, users will be able to launch it by either typing its name or clicking on the button that appears on the /start menu.

Clicking on this button will display your message. If you've entered several messages, the user will see a "Next" button that allows them to cycle through the responses.

Command Redirects

Admins can now create Custom Command Redirects, allowing a command to point to another in-bot command with deep-link parameters, such as subscribe_planabcdef1234-10. This enables the creation of custom commands that link directly to specific plans, coupons, and more, offering greater flexibility.

To create a Custom Command Redirect, use the prefix cmd: followed by the command you want to use (without the /). For example:

  • cmd:subscribe will link this custom command to the /subscribe command, making them function identically.

  • You can create more complex redirects, such as cmd:subscribe_coupon_discountcode, to automatically select a particular plan and apply a discount code.

Advanced Commands

If you have programming skills and knowledge, you can create advanced custom commands for your TGmembership-powered bot. To get started, type /custom_commands and click "Add" to create a new command, just like you would for a basic command. Instead of entering a message, click on the "Click through your own server" button and enter a URL address where your script is located. Whenever someone uses this command, TGmembership will forward the update from Telegram to your script, giving you the freedom to manipulate and use this data however you wish.

Here's an example of what a request might look like:

{
  "update_id": 123456789,
  "message": {
    "message_id": 1234,
    "from": {
      "id": 123456789,
      "is_bot": false,
      "first_name": "John Doe",
      "username": "JohnDoe",
      "language_code": "en"
    },
    "chat": {
      "id": 123456789,
      "first_name": "John Doe",
      "username": "JohnDoe",
      "type": "private"
    },
    "date": 1680192827,
    "text": "More complex command"
  }
}

With the API token and the data provided in the request, you have all the tools you need to execute any logic your command may require. You can query Telegram's API directly and manipulate the data as needed to achieve your desired outcome.

Now, whenever someone starts your bot they will see both commands. When users click on the "My first custom command", the bot will reply with your predefined messages. When users click on the "More complex command", the bot will send a request to your own server, where you can process the data and respond however you want.

Last updated