A telegram bot in Julia

A telegram bot in Julia

I just want to see source code.


Fetching and replying of telegram bot messages can be handle by HTTP.jl easily, unless you forget to escape uri with percentages. Because the main use case is to respond to commands in telegram, I used a Dict() approach where we give the bot a dictionary of functions so that whenever it sees matching commands, it will reply with the result of that function (given parameter).

using telegram

botApi = "<your_api>"

function echo(incoming::AbstractString)
    return incoming
end

txtCmds = Dict()
txtCmds["repeat_msg"] = echo #this will respond to '/repeat_msg <any thing>'
txtCmds["start"] = x -> "Welcome to my bot" # this will respond to '/start'

telegram.startBot(botApi; textHandle = txtCmds)

The inline mode is still missing, any help is appreciated!
Thx to the PR from simeonschaub, now that the bot has an inline mode! The example code is shown below, where I modified upon their PR to make the invoking style matching.

using Telegrambot
using UUIDs
botApi = "bot<your_api_key>"

function welcomeMsg(incoming::AbstractString)
    return "Welcome to my awesome bot"
end

function echo(incoming::AbstractString)
    return incoming
end

txtCmds = Dict()
txtCmds["repeat_msg"] = echo #this will respond to '/repeat_msg <any thing>'
txtCmds["start"] = welcomeMsg # this will respond to '/start'

inlineOpts = Dict() #Title, result pair
inlineOpts["Make Uppercase"] = uppercase #this will generate an pop-up named Make Uppercase and upon tapping return uppercase(<user_input>)

#uppercase is a function that takes a string and return the uppercase version of that string

startBot(botApi; textHandle = txtCmds, inlineQueryHandle=inlineOpts)