|
| 1 | +# Telegram bot menu |
| 2 | + |
| 3 | +Telegram bot with universal editable menu. With this program, you do not need to write code for the bot with the menu. Just run the bot and configure its menu via Telegram. |
| 4 | + |
| 5 | +## Getting Started |
| 6 | + |
| 7 | +1. Create bot with official Telegram robot [@BotFather](http://t.me/BotFather) |
| 8 | +2. Set [TOKEN](https://github.com/zZoMROT/telegram-bot-menu/blob/master/init.js#L9) variable in init.js |
| 9 | + ``` |
| 10 | + var TOKEN = '<YOUR_TOKEN>'; |
| 11 | + ``` |
| 12 | +3. Make sure that you have installed the utility Sed. This is necessary to configure bot. To work with finished configuration file, this is not necessary. |
| 13 | + ``` |
| 14 | + apt-get install sed |
| 15 | + ``` |
| 16 | +4. Start program with |
| 17 | + ``` |
| 18 | + node bot.js menu data edit |
| 19 | + ``` |
| 20 | + |
| 21 | +## Syntax |
| 22 | + |
| 23 | +``` |
| 24 | +node bot.js menu.file data.folder [mode [username|telegram_id|all]] |
| 25 | +``` |
| 26 | + |
| 27 | +* **menu.file** |
| 28 | + File with menu |
| 29 | +* **data.folder** |
| 30 | + Path to folder with payload which bot responds when the buttons is clicked |
| 31 | +* **mode [username|telegram_id|all]** |
| 32 | + Bot mode. |
| 33 | + Use **edit** to configurate menu. |
| 34 | + You can use users **username** and **telegram_id**, separated by commas, for differentiation of access to edit menu. |
| 35 | + If you use **all** or nothing then all users can edit menu. |
| 36 | + |
| 37 | + |
| 38 | +## Edit mode |
| 39 | + |
| 40 | +In this mode you can: |
| 41 | +* click buttons as standart menu |
| 42 | +* click buttons without actions with buttons *BUTTON|wa* for testing the menu tree |
| 43 | +* edit actions for buttons |
| 44 | +* delete buttons |
| 45 | +* create buttons |
| 46 | +* export menu to special file which you can import in future |
| 47 | +* import menu from special file |
| 48 | + |
| 49 | +## Menu file |
| 50 | + |
| 51 | + File with menu catalogs in format |
| 52 | + ``` |
| 53 | + PARRENT:::CATALOG:::BUTTON[:::ACTION[:::ACTION[...]]] |
| 54 | + ``` |
| 55 | + In this file there must be at least one line with PARRENT=root |
| 56 | + For successful start in the configuration file one line is enough: |
| 57 | + ``` |
| 58 | + root:::main:::button1 |
| 59 | + ``` |
| 60 | + Actions must be in json format for each action, for example: |
| 61 | + ``` |
| 62 | + {"type":"text","value":"hello world!"} |
| 63 | + ``` |
| 64 | + |
| 65 | + **Action types:** |
| 66 | + * text |
| 67 | + * voice |
| 68 | + * sticker |
| 69 | + * photo |
| 70 | + * video |
| 71 | + * location |
| 72 | + * document |
| 73 | + * contact |
| 74 | + |
| 75 | +For *location* action value use next format: longitude_latitude |
| 76 | +``` |
| 77 | +root:::main:::button1:::{"type":"location","value":"-73.935242_40.730610"} |
| 78 | +``` |
| 79 | +For *contact* action value use next format: phone_name |
| 80 | +``` |
| 81 | +root:::main:::button1:::{"type":"contact","value":"79001112233_Bob"} |
| 82 | +``` |
| 83 | +For *voice*, *sticker*, *photo*, *video* and *document* actions value use path to file for import (see section **Export and Import menu**) or file_id from Telegram to which the bot has access. |
| 84 | +``` |
| 85 | +root:::main:::button1:::{"type":"photo","value":"data/file_1.jpg"} |
| 86 | +``` |
| 87 | +``` |
| 88 | +root:::main:::button1:::{"type":"photo","value":"AgADAgADD6kxGyCP4UgS5DhiGXJJgYLdtw4ABLJZLw2sc33Mx20DAAEC"} |
| 89 | +``` |
| 90 | +## Export and Import menu |
| 91 | +You can export and import menu when bot started with edit mode. |
| 92 | +For export your menu to file *menu.export* you can use command **/export menu.export** in bot chat, it's start bot to dowanload all actions load from Telegram to *data.folder* and create file with menu for import. |
| 93 | + |
| 94 | +For import your menu from file *menu.export* you can use command **/import menu.export** in bot chat, it's start bot to upload all actions load from *data.folder* to Telegram and modify your *menu.file* with new data from *menu.export*. |
| 95 | + |
| 96 | +In file *menu.export* actions value indicate a local file, but bot use Telegram file_id in work. If you want create *menu.file* by yourself without Telegram and you use *voice*, *sticker*, *photo*, *video* or *document* actions, you need import. |
0 commit comments