2025-09-26 18:41:11 -07:00
|
|
|
# run with `./build/bot_echo`
|
|
|
|
|
|
|
|
|
|
import chronicles
|
|
|
|
|
import chronos
|
|
|
|
|
|
2025-12-16 19:46:19 -08:00
|
|
|
import chat
|
2025-09-26 18:41:11 -07:00
|
|
|
import content_types
|
|
|
|
|
|
|
|
|
|
proc main() {.async.} =
|
|
|
|
|
|
2025-10-15 16:20:54 -07:00
|
|
|
let dsConfig = DefaultConfig()
|
|
|
|
|
let ident = createIdentity("EchoBot")
|
2025-09-26 18:41:11 -07:00
|
|
|
var chatClient = newClient(dsConfig, ident)
|
|
|
|
|
|
2025-10-15 16:20:54 -07:00
|
|
|
chatClient.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
|
2025-09-26 18:41:11 -07:00
|
|
|
info "New Message: ", convoId = convo.id(), msg= msg
|
2025-12-16 19:46:19 -08:00
|
|
|
discard await convo.sendMessage(msg.content)
|
2025-09-26 18:41:11 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
chatClient.onNewConversation(proc(convo: Conversation) {.async.} =
|
|
|
|
|
info "New Conversation Initiated: ", convoId = convo.id()
|
2025-12-16 19:46:19 -08:00
|
|
|
discard await convo.sendMessage(initTextFrame("Hello!").toContentFrame().encode())
|
2025-09-26 18:41:11 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await chatClient.start()
|
|
|
|
|
|
|
|
|
|
info "EchoBot started"
|
|
|
|
|
info "Invite", link=chatClient.createIntroBundle().toLink()
|
|
|
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
|
waitFor main()
|
|
|
|
|
runForever()
|