https://github.com/solapi/solapi-agent
Agent for SOLAPI Services
https://github.com/solapi/solapi-agent
Last synced: 6 months ago
JSON representation
Agent for SOLAPI Services
- Host: GitHub
- URL: https://github.com/solapi/solapi-agent
- Owner: solapi
- Created: 2020-10-11T17:05:03.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-05-26T05:06:26.000Z (about 1 year ago)
- Last Synced: 2025-05-26T06:25:48.780Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 22.3 MB
- Stars: 0
- Watchers: 0
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Solapi Agent
## ๐ ์ฃผ์์ฌํญ ๐
* ๋ ์ด์ ์๋ผํผ DB ์ฐ๋ํ ์์ด์ ํธ๋ ์ ์ง๋ณด์ ๋์ง ์์ต๋๋ค.
* ๋ฌธ์๋ฅผ ํตํด [API ๊ฐ๋ฐ์ฐ๋](https://developers.solapi.com/references/messages/sendManyDetail)์ ์งํํด์ฃผ์๊ฑฐ๋, [SOLAPI Github](https://github.com/solapi) ๋ด SDK๋ฅผ ํตํด ๊ฐ๋ฐ์ฐ๋์ ์งํํด์ฃผ์๊ธฐ ๋ฐ๋๋๋ค.
## ๊ฐ์
DB INSERT๋ก ์นด์นด์คํก ๋ฐ ๋ฌธ์๋ฅผ ๋ฐ์ก ํ ์ ์๋๋ก go์ธ์ด๋ก ์์ฑ๋์์ต๋๋ค.
ํ์ฌ Agent๋ go ์ปดํ์ผ๋ฌ(go 1.18 ๊ธฐ์ค)๋ก ์๋ก ๋น๋ํ์
์ผ ํฉ๋๋ค.
## DB ์ค๋น
> MySQL ๋ฒ์ 5.7.14 ์ด์์ ์ค๋นํด์ฃผ์ธ์.
> ํน์ MariaDB ๋ฒ์ 10.2 ์ด์์ ์ค๋นํด์ฃผ์ธ์.
์๋ ๋ด์ฉ์ผ๋ก DB ๋ฐ ๊ณ์ ์ ๋ง๋ค์ด ์ฃผ์ธ์.
```
CREATE DATABASE msg;
CREATE USER 'msg'@'localhost' IDENTIFIED BY 'msg';
GRANT ALL PRIVILEGES ON msg.* TO 'msg'@'localhost';
```
์๋ ์คํค๋ง๋ก ํ
์ด๋ธ์ ๋ง๋ค์ด ์ฃผ์ธ์. (MariaDB๋ create_table_maria.sql ์ฐธ๊ณ )
```
CREATE TABLE msg (
id integer AUTO_INCREMENT primary key,
createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
scheduledAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
sendAttempts SMALLINT NOT NULL DEFAULT 0,
reportAttempts SMALLINT NOT NULL DEFAULT 0,
`to` VARCHAR(20) AS (payload->>'$.to') STORED,
`from` VARCHAR(20) AS (payload->>'$.from') STORED,
groupId VARCHAR(255) AS (result->>'$.groupId') STORED,
messageId VARCHAR(255) AS (result->>'$.messageId') STORED,
status VARCHAR(20) AS (result->>'$.status') STORED,
statusCode VARCHAR(255) AS (result->>'$.statusCode') STORED,
statusMessage VARCHAR(255) AS (result->>'$.statusMessage') STORED,
payload JSON,
result JSON default NULL,
sent BOOLEAN NOT NULL default false,
KEY (`createdAt`),
KEY (`updatedAt`),
KEY (`scheduledAt`),
KEY (`sendAttempts`),
KEY (`reportAttempts`),
KEY (`to`),
KEY (`from`),
KEY (groupId),
KEY (messageId),
KEY (status),
KEY (statusCode),
KEY (sent)
) DEFAULT CHARSET=utf8mb4;
```
## ์์ค ์ฝ๋ ๋น๋
์๋ ๋ช
๋ น์ผ๋ก ๋น๋ํ๋ฉด agent ์คํํ์ผ์ด ์์ฑ๋ฉ๋๋ค.
```
go build ./cmd/agent/agent.go
```
## ์๋น์ค ๋ฐ๋ชฌ ์ค์น
๋น๋๋ agent ํ์ผ์ /opt/agent ๋๋ ํ ๋ฆฌ๋ฅผ ๋ง๋ค๊ณ ์๋๋ก ๋ณต์ฌํฉ๋๋ค.
```
mkdir -p /opt/agent
cp ./agent /opt/agent/agent
```
/opt/agent/db.json ํ์ผ์ ๋ง๋ค๊ณ DB์ ์ ์ ๋ณด๋ฅผ ์
๋ ฅํฉ๋๋ค.
```
vi /opt/agent/db.json
```
db.json ์์
```
{
"provider": "mysql",
"dbname": "msg",
"table": "msg",
"user": "root",
"password": "root-password",
"host": "localhost",
"port": 3306
}
```
/opt/agent/config.json ํ์ผ์ ๋ง๋ค๊ณ API Key์ ๋ณด๋ฅผ ์
๋ ฅํฉ๋๋ค.
```
vi /opt/agent/config.json
```
config.json ์์
```
{
"APIKey": "๋ฐ๊ธ๋ฐ์ API Key ์
๋ ฅ",
"APISecret": "๋ฐ๊ธ๋ฐ์ API Secret Key ์
๋ ฅ",
"Protocol": "https",
"Domain": "api.solapi.com",
"Prefix": "",
"AppId": "",
"AllowDuplicates": true
}
```
Prefix, AppId๋ ๋น์๋์๋ฉด ๋ฉ๋๋ค.
AllowDuplicates๊ฐ์ด true์ด๋ฉด ๋์๊ฐ๋ ๊ฐ์ ์์ ๋ฒํธ๋ก ์ฌ๋ฌ๊ฑด ๋ฐ์ก์ด ๊ฐ๋ฅํ๊ณ , false์ด๋ฉด ํ๊ฑด๋ง ๋ฐ์ก๋๊ณ ๋๋จธ์ง๋ ์ค๋ณต๊ฑด์ผ๋ก ๋ฐ์ก ์คํจ๋ฉ๋๋ค.
## ์๋น์ค ๋ฐ๋ชฌ ์คํ
์๋น์ค ๋ฐ๋ชฌ์ ์์คํ
์ ๋ฑ๋ก ๋ฐ ์คํํฉ๋๋ค. (๋ชจ๋ ๋ช
๋ น์ root ๊ถํ์ผ๋ก ์คํํด์ผ ํฉ๋๋ค.)
```
./agent install
./agent start
```
๊ธฐ๋ณธ ์ค์น ๊ฒฝ๋ก(/opt/agent)์ ๋ค๋ฅด๊ฒ ์ค์นํ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด AGENT_HOME ํ๊ฒฝ๋ณ์๋ฅผ ์ค์ ํด ์ฃผ์ธ์
```
export AGENT_HOME=/home/ubuntu/agent
```
## ์๋น์ค ๋ฐ๋ชฌ ๋ช
๋ น
์์คํ
์ ๋ฑ๋ก
```
./agent install
```
๋ฐ๋ชฌ ์คํ
```
./agent start
```
๋ฐ๋ชฌ ์ํ
```
./agent status
```
๋ฐ๋ชฌ ์ ์ง
```
./agent stop
```
์์คํ
์์ ์ ๊ฑฐ
```
./agent remove
```