Background
SimpleX Chat, which is the first messenger without user IDs and privacy-focused, is also an open source project and you could self host the server as you like. But it's not many bot tutorials and deploy it simply. As a blog said, it has to use CLI
to be gateway/bridge to communicate between SMP Server
and your bot server.
Architecture
What I Expected
I want to put the CLI
to the docker container so I could deploy it easily.
But I faced the issue that I need to input the username to create user profile when running the CLI
at the first time, and there is no CLI
option to set it. To make matters worse, some APIs like create group
didn't work in typescript SDK.
What I did
So I forked the repo to fix the problems of CLI
and SDK
, and created a repo to show how to dockerize the CLI
and build a bot server.
Dockerize CLI
I add --display-name
option to the CLI
so I could create user profile with non-interactive mode. I created a docker image named feimeizhan/simplex-chat-gateway
which code is here.
Typescript SDK
I fixed the issue like create group
error and no group list
, and publish as @reply2future/simplex-chat
which code is here
bot-center
I also created a bot example to show how to use typescript sdk.
How to Use simplex-chat-gateway
Requirements
docker
anddocker-compose
- Linux system
Steps
- Run the comand
git clone https://github.com/reply2future/simplex-chat-gateway.git
to clone the repo and cd to the directory of repo. - Copy
.env.template
to.env
in current directory, and change the environment variables as you need. - Run the command
docker compose up -d
- You could see the
bot address
andgroupId
in the console of docker containerbot-center
like below: - You need to add the bot by paste the bot address to your simplex-chat client, and the bot accepts the friend request automatically, and you could see the
contact_id
of your user profile. - Send a message like
/square-num 8
which is pre-defined handler inbot-center
, then the bot would reply8 * 8 = 64
- (Optional) add you to the pre-created group like
Notification
by calling the api ofbot-center
likehttp://localhost:6794/invite/:contact_id
, the more information you could see the code here, so you could send message to the group frombot-center
by using api likehttp://localhost:6794/notification/:group_id
.
How to Create your handler in bot-center
I will show it how to add your handler to bot-center
Requirements
TypeScript
Steps
- Go to the
bot-center
directory - Create a handler in
./handlers
directory, like./handlers/direct/echo.ts
- Implement interface
IHandler
inecho.ts
- Add
echo.ts
to./handlers/index.ts
, like['echo', new EchoHandler()]
- Deploy your
bot-center
- Test it by sending a direct message to bot like
/echo test
More SDKs
The official supported SDK is TypeScript, but you could create your SDK using your familiar programming language, because it uses websocket.
Why no windows/macOS
Because of the secure reason the SimpleX-Chat agent will bind 127.0.0.1
only, and network_mode: host
is not supported in a meaningful way on macOS and Windows due to Docker's reliance on a VM architecture, so it doesn't work in macos and windows.