-
Notifications
You must be signed in to change notification settings - Fork 63
Using Swift REPL for calling API methods
Andrey Fidrya edited this page Jun 9, 2016
·
8 revisions
A read–eval–print loop (REPL) allows executing arbitrary Swift commands and seeing their output instantly.
Clone the library and build any sample project:
git clone https://github.com/zmeyc/telegram-bot-swift.git
cd telegram-bot-swift/Examples/hello-bot
swift build
Currently there are unresolved issues with importing frameworks when running REPL directly, so as a workaround let's run it using lldb:
export HELLO_BOT_TOKEN="token obtained from BotFather"
lldb -o run .build/debug/hello-bot
Expected output:
(lldb) target create ".build/debug/hello-bot"
Current executable set to '.build/debug/hello-bot' (x86_64).
(lldb) run
endpoint: getMe, data:
Ready to accept commands
Send something to your bot and write down from.id
:
{
"update_id" : 642225283,
"message" : {
...
"from" : {
"username" : "username",
"id" : 78440479, <----------- from.id
"last_name" : "Lastname",
"first_name" : "Firstname"
}
}
}
Press CTRL-C
to pause execution, then at lldb prompt type:
repl
REPL prompt will appear:
1>
Note that when using Xcode, you can skip all of this and simply place a breakpoint in main loop, then in debugger run repl
.
Init a bot instance:
import TelegramBot
let bot = TelegramBot(token: readToken("HELLO_BOT_TOKEN"))
Bot is now ready to execute commands.