SimpleX-Chat/apps/simplex-chat/Main.hs
Evgeny Poberezkin b7860ad0e8
simplex-chat server & JavaScript/TypeScript SDK/client (#539)
* simplex-chat server

* typescript types for chat commands and command serialization

* typescript ChatResponse type

* more types

* more types

* websocket chat client

* aligb ts/haskell types

* chat server & TS client via websockets - it works

* TS chat client test

* TS chat client test

* update test

* more api functions

* more api methods, refactor, readme

* squaring chat bot example, fixes

* update readme

* remove console.log

* npm version 0.1.0
2022-05-13 19:44:03 +01:00

36 lines
1.2 KiB
Haskell

{-# LANGUAGE NamedFieldPuns #-}
module Main where
import Control.Concurrent (threadDelay)
import Server
import Simplex.Chat.Controller (versionNumber)
import Simplex.Chat.Core
import Simplex.Chat.Options
import Simplex.Chat.Terminal
import Simplex.Chat.View (serializeChatResponse)
import System.Directory (getAppUserDataDirectory)
import System.Terminal (withTerminal)
main :: IO ()
main = do
appDir <- getAppUserDataDirectory "simplex"
opts@ChatOpts {chatCmd, chatServerPort} <- getChatOpts appDir "simplex_v1"
if null chatCmd
then case chatServerPort of
Just chatPort ->
simplexChatServer defaultChatServerConfig {chatPort} terminalChatConfig opts
_ -> do
welcome opts
t <- withTerminal pure
simplexChatTerminal terminalChatConfig opts t
else simplexChatCore terminalChatConfig opts Nothing $ \_ cc -> do
r <- sendChatCmd cc chatCmd
putStrLn $ serializeChatResponse r
threadDelay $ chatCmdDelay opts * 1000000
welcome :: ChatOpts -> IO ()
welcome ChatOpts {dbFilePrefix} = do
putStrLn $ "SimpleX Chat v" ++ versionNumber
putStrLn $ "db: " <> dbFilePrefix <> "_chat.db, " <> dbFilePrefix <> "_agent.db"
putStrLn "type \"/help\" or \"/h\" for usage info"