mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-25 16:57:33 +00:00
6 lines
10 KiB
JSON
6 lines
10 KiB
JSON
{
|
||
"name": "Telegram-bot-bash",
|
||
"tagline": "Telegram bot written in bash",
|
||
"body": "#bashbot\r\nA Telegram bot written in bash.\r\n\r\nUses [json.sh](https://github.com/dominictarr/JSON.sh) and tmux (for interactive chats).\r\n\r\n\r\n## Instructions\r\n### Create your first bot\r\n\r\n1. Message @botfather https://telegram.me/botfather with the following\r\ntext: `/newbot`\r\n If you don't know how to message by username, click the search\r\nfield on your Telegram app and type `@botfather`, you should be able\r\nto initiate a conversation. Be careful not to send it to the wrong\r\ncontact, because some users has similar usernames to `botfather`.\r\n\r\n ![botfather initial conversation](http://i.imgur.com/aI26ixR.png)\r\n\r\n2. @botfather replies with `Alright, a new bot. How are we going to\r\ncall it? Please choose a name for your bot.`\r\n\r\n3. Type whatever name you want for your bot.\r\n\r\n4. @botfather replies with `Good. Now let's choose a username for your\r\nbot. It must end in `bot`. Like this, for example: TetrisBot or\r\ntetris_bot.`\r\n\r\n5. Type whatever username you want for your bot, minimum 5 characters,\r\nand must end with `bot`. For example: `telesample_bot`\r\n\r\n6. @botfather replies with:\r\n\r\n Done! Congratulations on your new bot. You will find it at\r\ntelegram.me/telesample_bot. You can now add a description, about\r\nsection and profile picture for your bot, see /help for a list of\r\ncommands.\r\n\r\n Use this token to access the HTTP API:\r\n <b>123456789:AAG90e14-0f8-40183D-18491dDE</b>\r\n\r\n For a description of the Bot API, see this page:\r\nhttps://core.telegram.org/bots/api\r\n\r\n7. Note down the 'token' mentioned above.\r\n\r\n8. Type `/setprivacy` to @botfather.\r\n\r\n ![botfather later conversation](http://i.imgur.com/tWDVvh4.png)\r\n\r\n9. @botfather replies with `Choose a bot to change group messages settings.`\r\n\r\n10. Type `@telesample_bot` (change to the username you set at step 5\r\nabove, but start it with `@`)\r\n\r\n11. @botfather replies with\r\n\r\n 'Enable' - your bot will only receive messages that either start\r\nwith the '/' symbol or mention the bot by username.\r\n 'Disable' - your bot will receive all messages that people send to groups.\r\n Current status is: ENABLED\r\n\r\n12. Type `Disable` to let your bot receive all messages sent to a\r\ngroup. This step is up to you actually.\r\n\r\n13. @botfather replies with `Success! The new status is: DISABLED. /help`\r\n\r\n### Install bashbot \r\nClone the repository: \r\n```\r\ngit clone https://github.com/topkecleon/telegram-bot-bash\r\n```\r\n\r\nPaste the token on line 15 (instead of tokenhere). \r\nThen start editing the commands. \r\n \r\n### Receive data \r\nYou can read incoming data using the following variables: \r\n\r\n* ```$MESSAGE```: Incoming messages \r\n* ```$CAPTION```: Captions \r\n* ```$USER```: This array contains the First name, last name, username and user id of the sender of the current message.\r\n * ```${USER[ID]}```: User id \r\n * ```${USER[FIRST_NAME]}```: User's first name \r\n * ```${USER[LAST_NAME]}```: User's last name \r\n * ```${USER[USERNAME]}```: Username \r\n* ```$URLS```: This array contains documents, audio files, stickers, voice recordings and stickers stored in the form of URLs.\r\n * ```${URLS[AUDIO]}```: Audio files \r\n * ```${URLS[VIDEO]}```: Videos \r\n * ```${URLS[PHOTO]}```: Photos (maximum quality) \r\n * ```${URLS[VOICE]}```: Voice recordings \r\n * ```${URLS[STICKER]}```: Stickers \r\n * ```${URLS[DOCUMENT]}```: Any other file \r\n* ```$CONTACT```: This array contains info about contacts sent in a chat.\r\n * ```${CONTACT[NUMBER]}```: Phone number \r\n * ```${CONTACT[FIRST_NAME]}```: First name \r\n * ```${CONTACT[LAST_NAME]}```: Last name \r\n * ```${CONTACT[ID]}```: User id \r\n* ```$LOCATION```: This array contains info about locations sent in a chat.\r\n * ```${LOCATION[LONGITUDE]}```: Longitude \r\n * ```${LOCATION[LATITUDE]}```: Latitude \r\n\r\n### Usage \r\nTo send messages use the ```send_message``` function: \r\n```\r\nsend_message \"${USER[ID]}\" \"lol\" \r\n``` \r\nTo send html or markdown put the following strings before the text, depending on the parsing mode you want to enable: \r\n```\r\nsend_message \"${USER[ID]}\" \"markdown_parse_mode lol *bold*\" \r\n``` \r\n```\r\nsend_message \"${USER[ID]}\" \"html_parse_mode lol <b>bold</b>\" \r\n``` \r\nThis function also allows a third parameter that disables additional function parsing (for safety use this when reprinting user input): \r\n```\r\nsend_message \"${USER[ID]}\" \"lol\" \"safe\"\r\n``` \r\nTo send images, videos, voice files, photos ecc use the ```send_photo``` function (remember to change the safety Regex @ line 94 to allow sending files only from certain directories): \r\n```\r\nsend_file \"${USER[ID]}\" \"/home/user/doge.jpg\" \"Lool\"\r\n```\r\nTo send custom keyboards use the ```send_keyboard``` function: \r\n```\r\nsend_keyboard \"${USER[ID]}\" \"Text that will appear in chat?\" \"Yep\" \"No\"\r\n``` \r\nTo send locations use the ```send_location``` function: \r\n```\r\nsend_location \"${USER[ID]}\" \"Latitude\" \"Longitude\"\r\n``` \r\nTo send venues use the ```send_venue``` function: \r\n```\r\nsend_venue \"${USER[ID]}\" \"Latitude\" \"Longitude\" \"Title\" \"Address\" \"optional foursquare id\"\r\n``` \r\nTo forward messages use the ```forward``` function: \r\n```\r\nforward \"${USER[ID]}\" \"from_chat_id\" \"message_id\"\r\n``` \r\nTo send a chat action use the ```send_action``` function.\r\nAllowed values: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_audio or upload_audio for audio files, upload_document for general files, find_location for locations. \r\n```\r\nsend_action \"${USER[ID]}\" \"action\"\r\n``` \r\n\r\nTo create interactive chats, write (or edit the question script) a normal bash (or C or python) script, chmod +x it and then change the argument of the startproc function to match the command you usually use to start the script. \r\nThe text that the script will output will be sent in real time to the user, and all user input will be sent to the script (as long as it's running or until the user kills it with /cancel). \r\nTo open up a keyboard in an interactive script, print out the keyboard layout in the following way: \r\n```\r\necho \"Text that will appear in chat? mykeyboardstartshere \\\"Yep, sure\\\" \\\"No, highly unlikely\\\"\"\r\n``` \r\nSame goes for files:\r\n```\r\necho \"Text that will appear in chat? myfilelocationstartshere /home/user/doge.jpg\"\r\n``` \r\nAnd locations: \r\n```\r\necho \"Text that will appear in chat. mylatstartshere 45 mylongstartshere 45\"\r\n``` \r\nAnd venues: \r\n```\r\necho \"Text that will appear in chat. mylatstartshere 45 mylongstartshere 45 mytitlestartshere my home myaddressstartshere Diagon Alley N. 37\"\r\n``` \r\nYou can combine them:\r\n```\r\necho \"Text that will appear in chat? mykeyboardstartshere \\\"Yep, sure\\\" \\\"No, highly unlikely\\\" myfilelocationstartshere /home/user/doge.jpg mylatstartshere 45 mylongstartshere 45\"\r\n``` \r\nPlease note that you can either send a location or a venue, not both. To send a venue add the mytitlestartshere and the myaddressstartshere keywords. \r\n\r\nThe following commands allows users to interact with your bot via *inline queries*.\r\nIn order to enable **inline mode**, send `/setinline` command to [@BotFather](https://telegram.me/botfather) and provide the placeholder text that the user will see in the input field after typing your bot’s name.\r\nAlso, edit line 21 from `bashbot.sh` putting a \"1\". \r\nNote that you can't modify the first two parameters of the function `answer_inline_query`, only the ones after them.\r\n\r\nTo send messsages or links through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"article\" \"Title of the result\" \"Content of the message to be sent\"\r\n```\r\nTo send photos in jpeg format and less than 5MB, from a website through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"photo\" \"A valid URL of the photo\" \"URL of the thumbnail\"\r\n```\r\nTo send standard gifs from a website (less than 1MB) through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"gif\" \"gif url\"\r\n```\r\nTo send mpeg4 gifs from a website (less than 1MB) through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"mpeg4_gif\" \"mpeg4 gif url\"\r\n```\r\nTo send videos from a website through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"video\" \"valid video url\" \"Select one mime type: text/html or video/mp4\" \"URL of the thumbnail\" \"Title for the result\"\r\n```\r\nTo send photos stored in Telegram servers through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"cached_photo\" \"identifier for the photo\"\r\n```\r\nTo send gifs stored in Telegram servers through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"cached_gif\" \"identifier for the gif\"\r\n```\r\nTo send mpeg4 gifs stored in Telegram servers through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"cached_mpeg4_gif\" \"identifier for the gif\"\r\n```\r\nTo send stickers through an *inline query*:\r\n```\r\nanswer_inline_query \"$iQUERY_ID\" \"cached_sticker\" \"identifier for the sticker\"\r\n```\r\n\r\n\r\nTo modify the responses to commands edit the commands.sh file (this should ease upgrades of the bot core). \r\n\r\nOnce you're done editing start the bot with ```./bashbot.sh start```. If you want to do some more changes make them and then rerun the same command. \r\nTo stop the bot run ```./bashbot.sh kill```. \r\nIf some thing doesn't work as it should, debug with ```bash -x bashbot.sh```. \r\n\r\nTo use the functions provided in this script in other scripts simply source bashbot: ```source bashbot.sh``` \r\n\r\n\r\n## User count \r\nTo count the total number of users that ever used the bot run the following command: \r\n```\r\nbash bashbot.sh count\r\n``` \r\n\r\n\r\n## Sending broadcasts to all users \r\nTo send a broadcast to all of users that ever used the bot run the following command: \r\n```\r\nbash bashbot.sh broadcast \"Hey! I just wanted to let you know that the bot's been updated!\"\r\n``` \r\n\r\n\r\n\r\n\r\nThat's it!\r\n\r\nIf you feel that there's something missing or if you found a bug, feel free to submit a pull request!\r\n",
|
||
"note": "Don't delete this file! It's used internally to help with page regeneration."
|
||
} |