Skip to content

Instantly share code, notes, and snippets.

@gsamat
Created February 6, 2017 13:29
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save gsamat/5c52728c2469220ed57c1b9435860ac2 to your computer and use it in GitHub Desktop.
Save gsamat/5c52728c2469220ed57c1b9435860ac2 to your computer and use it in GitHub Desktop.
#!/bin/sh
# CONFIGURATION
# 1. Go to @botfather and create a bot and use it's auth token as bot_token value
# 2. Create test channel, believe me, you need it
# 3. Set some url for your test channel
# 4. Add your bot to both channels, set their names in variables
# USAGE
# 1. Copy your markdown-formatted message into OS clipboard (Cmd+C)
# 2. Run markdown-telegram.sh to receive your message in test channel
# 3. If everything is OK, run it again, this time as ./markdown-telegram.sh production
bot_token=YOUBOTTOKENHERE
test_channel=YOURTESTCHANNELHERE
production_channel=YOURPRODUCTIONCHANNELHERE
error () {
echo $1 >&2;
exit 1
}
[ $bot_token ] || error "configure \$bot_token"
[ $test_channel ] || error "configure \$test_channel"
[ $production_channel ] || error "configure \$production_channel"
channel=$test_channel
[ $1 ] && [ $1 = production ] && channel=$production_channel
## Request
curl -X "POST" "https://api.telegram.org/bot$bot_token/sendMessage" \
-H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" \
--data-urlencode "text=`pbpaste`" \
--data-urlencode "chat_id=@$channel" \
--data-urlencode "disable_web_page_preview=true" \
--data-urlencode "parse_mode=markdown"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment