mirror of
https://github.com/logos-messaging/logos-chat.git
synced 2026-08-03 00:23:27 +00:00
Add EchoBot
This commit is contained in:
parent
da7bada6b3
commit
35274b6ec4
5
Makefile
5
Makefile
@ -87,9 +87,10 @@ nim_chat_poc: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
|||||||
\
|
\
|
||||||
$(ENV_SCRIPT) nim nim_chat_poc $(NIM_PARAMS) nim_chat_poc.nims
|
$(ENV_SCRIPT) nim nim_chat_poc $(NIM_PARAMS) nim_chat_poc.nims
|
||||||
|
|
||||||
tui: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
# Ensure there is a nimble task with a name that matches the target
|
||||||
|
tui bot_echo: | build-waku-librln build-waku-nat nim_chat_poc.nims
|
||||||
echo -e $(BUILD_MSG) "build/$@" && \
|
echo -e $(BUILD_MSG) "build/$@" && \
|
||||||
$(ENV_SCRIPT) nim tui $(NIM_PARAMS) --path:src nim_chat_poc.nims
|
$(ENV_SCRIPT) nim $@ $(NIM_PARAMS) --path:src nim_chat_poc.nims
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|||||||
35
examples/bot_echo.nim
Normal file
35
examples/bot_echo.nim
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# run with `./build/bot_echo`
|
||||||
|
|
||||||
|
import chronicles
|
||||||
|
import chronos
|
||||||
|
|
||||||
|
import chat_sdk
|
||||||
|
import content_types
|
||||||
|
|
||||||
|
import ./tui/persistence # Temporary Workaround for PeerDiscovery
|
||||||
|
|
||||||
|
proc main() {.async.} =
|
||||||
|
|
||||||
|
let cfg = await getCfg("EchoBot")
|
||||||
|
# let dsConfig = DefaultConfig()
|
||||||
|
# let ident = createIdentity("EchoBot")
|
||||||
|
var chatClient = newClient(dsConfig, ident)
|
||||||
|
|
||||||
|
chatClient.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
||||||
|
info "New Message: ", convoId = convo.id(), msg= msg
|
||||||
|
await convo.sendMessage(chatClient.ds, msg)
|
||||||
|
)
|
||||||
|
|
||||||
|
chatClient.onNewConversation(proc(convo: Conversation) {.async.} =
|
||||||
|
info "New Conversation Initiated: ", convoId = convo.id()
|
||||||
|
await convo.sendMessage(chatClient.ds, initTextFrame("Hello!").toContentFrame())
|
||||||
|
)
|
||||||
|
|
||||||
|
await chatClient.start()
|
||||||
|
|
||||||
|
info "EchoBot started"
|
||||||
|
info "Invite", link=chatClient.createIntroBundle().toLink()
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
waitFor main()
|
||||||
|
runForever()
|
||||||
@ -66,7 +66,7 @@ proc main() {.async.} =
|
|||||||
saro.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
saro.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
||||||
echo " Saro <------ :: " & getContent(msg)
|
echo " Saro <------ :: " & getContent(msg)
|
||||||
await sleepAsync(10000)
|
await sleepAsync(10000)
|
||||||
await convo.sendMessage(saro.ds, initImage(
|
discard await convo.sendMessage(saro.ds, initImage(
|
||||||
"https://waku.org/theme/image/logo-black.svg"))
|
"https://waku.org/theme/image/logo-black.svg"))
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,12 +80,12 @@ proc main() {.async.} =
|
|||||||
raya.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
raya.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} =
|
||||||
echo " ------> Raya :: " & getContent(msg)
|
echo " ------> Raya :: " & getContent(msg)
|
||||||
await sleepAsync(10000)
|
await sleepAsync(10000)
|
||||||
await convo.sendMessage(raya.ds, initTextFrame("Pong").toContentFrame())
|
discard await convo.sendMessage(raya.ds, initTextFrame("Pong").toContentFrame())
|
||||||
)
|
)
|
||||||
|
|
||||||
raya.onNewConversation(proc(convo: Conversation) {.async.} =
|
raya.onNewConversation(proc(convo: Conversation) {.async.} =
|
||||||
echo " ------> Raya :: New Conversation: " & convo.id()
|
echo " ------> Raya :: New Conversation: " & convo.id()
|
||||||
await convo.sendMessage(raya.ds, initTextFrame("Hello").toContentFrame())
|
discard await convo.sendMessage(raya.ds, initTextFrame("Hello").toContentFrame())
|
||||||
)
|
)
|
||||||
raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
|
raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
|
||||||
echo " raya -- Read Receipt for " & msgId
|
echo " raya -- Read Receipt for " & msgId
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user