-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtelegram_api.own
33 lines (26 loc) · 935 Bytes
/
telegram_api.own
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std, http, json, functional
// Telegram API example
token = "YOUR_TOKEN"
def toParams(obj) {
str = ""
for k, v : obj
str += k + "=" + v + "&"
return str
}
def createRawUrl(method, params, token = "") = "https://api.telegram.org/bot" + token + "/" + method + "?"+params+"access_token="+token
def createUrl(method, params, token = "") = createRawUrl(method, toParams(params), token)
def invokeJson(method, params, callback) = http(createUrl(method, params, token), combine(::jsondecode, callback))
def invoke(method, params, callback) = http(createUrl(method, params, token), callback)
def sendMessage(text = "", chatId = 1) {
invoke("sendMessage", {
"chat_id": chatId,
"text": text
}, ::echo)
}
def getUpdates() = invoke("getUpdates", {}, ::echo)
// Get updates in chat
getUpdates()
// Send message to chatId 1
sendMessage("Hello", 1)
// Send message to channel
sendMessage("Hello", "@telegram_channel")