Skip to content

Commit

Permalink
Merge pull request #10 from pupilcc/dev
Browse files Browse the repository at this point in the history
v0.3.0
  • Loading branch information
pupilcc authored Oct 14, 2022
2 parents feb080d + c9d95e4 commit 7c29f54
Show file tree
Hide file tree
Showing 29 changed files with 236 additions and 257 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ COPY ./src src/
RUN mvn clean package -B -e

FROM amazoncorretto:8-alpine-jre
RUN echo "Asia/Shanghai" > /etc/timezone
COPY --from=MAVEN_BUILD target/*.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","app.jar"]
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

提供了 [Docker 镜像](https://hub.docker.com/r/pupilcc/pushbot),便于自建,也可直接使用我提供的 Bot,欢迎品尝~[点击此处添加 Bot](https://t.me/notification_me_bot))

## 功能
## 一、功能

* [推送消息](#推送消息)
* [推送模板消息](#推送模板消息)
* [推送 Docker Hub 自动构建成功消息](#DockerHub)

## 食用指南
## 二、食用指南

### Bot 命令说明

Expand All @@ -28,7 +29,7 @@
-|-|-|-
text|String|是|文字内容(当 photo 存在时可为空)
photo|String|否|图片文件或者图片外链
parse_mode|String|否|发送文字内容的样式,可以是 Markdown 或 HTML
parseMode|String|否|发送文字内容的样式,可以是 Markdown 或 HTML

```bash
# using get
Expand All @@ -44,6 +45,20 @@ curl -d "text=HelloWorld" -X POST https://pb.pupilcc.app/sendMessage/{chatToken}
curl -d "photo=https://xxx.com/xxxxx.jpg" -X POST https://pb.pupilcc.app/sendMessage/{chatToken}
```

### 推送模板消息

接口地址:`/sendTemplate/{chatToken}`

**参数说明:**

参数|类型|必须|说明
-|-|-|-
templateId|String|是|模板id
title|String|是|标题
content|String|否|内容

[查看现有模板样式](https://github.com/pupilcc/pushbot/blob/master/docs/template.md)

### <span id="DockerHub">推送 Docker Hub 自动构建成功消息</span>

接口地址:`/webhook/docker/{chatToken}`
Expand All @@ -57,7 +72,7 @@ curl -d "photo=https://xxx.com/xxxxx.jpg" -X POST https://pb.pupilcc.app/sendMes
Bot 不会识别和储存任何用户推送的消息,只会将推送消息发送给 Telegram 服务器。Bot 只会记录用户回话 id,此 id 是向 Telegram 推送消息的凭据。


## 自建指南
## 三、自建指南

### 食材

Expand Down
9 changes: 9 additions & 0 deletions docs/template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 模板消息

---

## 一、现有模板消息样式

* templateId: 1

![template_1](https://vip2.loli.io/2022/10/15/b4hgQOUfVHiXxLw.jpg)
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.pupilcc</groupId>
<artifactId>pushbot</artifactId>
<version>0.2.5</version>
<version>0.3.0</version>
<name>pushbot</name>
<description>telegram notification bot</description>

Expand Down Expand Up @@ -76,6 +76,12 @@
<artifactId>sqlite-jdbc</artifactId>
</dependency>

<dependency>
<groupId>com.pupilcc.common</groupId>
<artifactId>common-rest</artifactId>
<version>1.0.1</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/pupilcc/pushbot/config/BeanConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.pupilcc.pushbot.config;

import com.pengrad.telegrambot.TelegramBot;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConfig {
@Autowired
private BotProperties botProperties;
private final BotProperties botProperties;

public BeanConfig(BotProperties botProperties) {
this.botProperties = botProperties;
}

@Bean
public TelegramBot telegramBot() {
Expand Down
41 changes: 7 additions & 34 deletions src/main/java/com/pupilcc/pushbot/config/BotProperties.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
package com.pupilcc.pushbot.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
* Bot 配置项
*
* @author pupilcc
*/
@Configuration
@ConfigurationProperties(prefix = "bot")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BotProperties {
private String token;
private String domain;
private String startHint;
private String endHint;

public BotProperties() {}

public String getToken() {
return token;
}

public void setToken(String token) {
this.token = token;
}

public String getDomain() {
return domain;
}

public void setDomain(String domain) {
this.domain = domain;
}

public String getStartHint() {
return startHint;
}

public void setStartHint(String startHint) {
this.startHint = startHint;
}

public String getEndHint() {
return endHint;
}

public void setEndHint(String endHint) {
this.endHint = endHint;
}
}
10 changes: 5 additions & 5 deletions src/main/java/com/pupilcc/pushbot/config/SQLiteDialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.sql.Types;

public class SQLiteDialect extends Dialect {
public class SQLiteDialect extends Dialect {
public SQLiteDialect() {
registerColumnType(Types.BIT, "integer");
registerColumnType(Types.TINYINT, "tinyint");
Expand All @@ -34,10 +34,10 @@ public SQLiteDialect() {
registerColumnType(Types.CLOB, "clob");
registerColumnType(Types.BOOLEAN, "integer");

registerFunction( "concat", new VarArgsSQLFunction(StringType.INSTANCE, "", "||", "") );
registerFunction( "mod", new SQLFunctionTemplate( StringType.INSTANCE, "?1 % ?2" ) );
registerFunction( "substr", new StandardSQLFunction("substr", StringType.INSTANCE) );
registerFunction( "substring", new StandardSQLFunction( "substr", StringType.INSTANCE) );
registerFunction("concat", new VarArgsSQLFunction(StringType.INSTANCE, "", "||", ""));
registerFunction("mod", new SQLFunctionTemplate(StringType.INSTANCE, "?1 % ?2"));
registerFunction("substr", new StandardSQLFunction("substr", StringType.INSTANCE));
registerFunction("substring", new StandardSQLFunction("substr", StringType.INSTANCE));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextHolder.applicationContext = applicationContext;
}

public static ApplicationContext getApplicationContext() {
assertApplicationContext();
return applicationContext;
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextHolder.applicationContext = applicationContext;
}

public static <T> T getBean(String beanName) {
assertApplicationContext();
return (T) applicationContext.getBean(beanName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.pupilcc.pushbot.controller;

import com.pupilcc.common.rest.ApiResult;
import com.pupilcc.pushbot.entity.SendMessageDTO;
import com.pupilcc.pushbot.extension.ApiResult;
import com.pupilcc.pushbot.entity.TemplateMessageDTO;
import com.pupilcc.pushbot.service.MessageService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 消息控制器
*
* @author pupilcc
*/
@RestController
Expand All @@ -21,12 +23,25 @@ public MessageController(MessageService messageService) {

/**
* 给用户发送消息
* @param dto 消息体
*
* @param dto 消息体
* @param chatToken 用户token
* @return 响应消息
*/
@RequestMapping("/sendMessage/{chatToken}")
public ApiResult<Object> sendMessage(SendMessageDTO dto, @PathVariable String chatToken) {
return messageService.sendMessage(dto, chatToken);
}

/**
* 给用户发送模板消息
*
* @param message 请求参数
* @param chatToken 用户token
* @return 响应消息
*/
@RequestMapping("/sendTemplate/{chatToken}")
public ApiResult<Object> sendTemplateMessage(TemplateMessageDTO message, @PathVariable String chatToken) {
return messageService.sendTemplate(message, chatToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

/**
* WebHook 控制器
*
* @author pupilcc
*/
@RestController
Expand All @@ -23,7 +24,8 @@ public WebhookController(WebhookService webHookService) {

/**
* Telegram Webhook. 接收用户在 Telegram 端发送的消息
* @param update 消息
*
* @param update 消息
* @param botToken TelegramBotToken
*/
@RequestMapping("/{botToken}")
Expand All @@ -33,7 +35,8 @@ public void webhookTelegram(@RequestBody Update update, @PathVariable String bot

/**
* Docker 自动构建成功消息
* @param dto 消息
*
* @param dto 消息
* @param chatToken 用户Token
*/
@RequestMapping("/docker/{chatToken}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* Docker WebHook 消息
*
* @author pupilcc
*/
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Docker WebHook 消息 push_data 对象
*
* @author pupilcc
*/
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* Docker WebHook 消息 repository 对象
*
* @author pupilcc
*/
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

/**
* 发送消息的参数
*
* @author pupilcc
*/
@Data
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/pupilcc/pushbot/entity/TemplateMessageDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.pupilcc.pushbot.entity;

import lombok.Data;

/**
* 模板消息 DTO
*
* @author pupilcc
* @since 2022-06-23
*/
@Data
public class TemplateMessageDTO {
/**
* 消息模板id
*/
private Integer templateId;

/**
* 标题
*/
private String title;

/**
* 内容
*/
private String content;
}
17 changes: 8 additions & 9 deletions src/main/java/com/pupilcc/pushbot/extension/ApiErrorCode.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.pupilcc.pushbot.extension;

import com.pupilcc.common.rest.IErrorCode;

/**
* REST API 错误码
*
* @author MyBatis Plus
*/
public enum ApiErrorCode implements IErrorCode{
/**
* 失败
*/
FAILED(-1L, "failed"),
/**
* 成功
*/
SUCCESS(0L, "success"),
public enum ApiErrorCode implements IErrorCode {
/**
* 参数为空
*/
Expand All @@ -29,6 +24,10 @@ public enum ApiErrorCode implements IErrorCode{
* 图片为空
*/
IMG_NULL(-1L, "image null"),
/**
* 模板不存在
*/
TEMPLATE_NOT_EXIST(-1L, "template not exist"),

;

Expand Down
Loading

0 comments on commit 7c29f54

Please sign in to comment.