-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bot transfered from console to tg. * fix: invalid email error * feature: change telegram api repo * feature: keyboard test example * feature: add config file * feature: getting token for config * feature: add TelegramBotInterface * feature: bot letters ability done * fix: change type * feature: update test ci * feature: add badges in readme * fix: put user inside tests * feature: build and push image ci * fix: change pom path in Dockerfile * feature: simplify dockerfile * feature: del some ci steps & use diff java image * fix: add start arg & fix tests * feature: friendly commit👋 * Refactor (#9) * refactor: naming for IDs and small refactor * refactor: move bot's action to the interface * refactor: remove comments and unused lines * docs: UPD README.md * Unit tests (#10) * chore: add equals for Mailbox * test: add tests for units * Mailbox * User * test: refactor tests * test: tests from Message, UserRepository Co-authored-by: Margarita <[email protected]> * docs: update readme * test: fix test methods names * chore: delete unused UserState Co-authored-by: WoodieDudy <[email protected]>
- Loading branch information
1 parent
30598cc
commit 07aa2d5
Showing
33 changed files
with
857 additions
and
368 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Docker | ||
|
||
on: | ||
push: | ||
branches: ["master", "dev"] | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
# github.repository as <account>/<repo> | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
# This is used to complete the identity challenge | ||
# with sigstore/fulcio when running outside of PRs. | ||
id-token: write | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Docker buildx | ||
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf | ||
|
||
# Login against a Docker registry except on PR | ||
- name: Log into registry ${{ env.REGISTRY }} | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# Extract metadata (tags, labels) for Docker | ||
# https://github.com/docker/metadata-action | ||
- name: Extract Docker metadata | ||
id: meta | ||
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
|
||
- name: Build and push Docker image | ||
id: build-and-push | ||
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a | ||
with: | ||
context: . | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,7 @@ build/ | |
|
||
### Custom ### | ||
.idea | ||
*.class | ||
*.class | ||
|
||
### Secret ### | ||
/src/main/resources/config.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM maven:3.8.5-openjdk-17-slim AS build | ||
|
||
COPY src /app/src | ||
COPY pom.xml /app | ||
|
||
RUN mvn -B test -f /app/pom.xml clean package | ||
|
||
FROM eclipse-temurin:17.0.5_8-jre-ubi9-minimal | ||
|
||
COPY --from=build /app/target/MailgramBot-1.0-SNAPSHOT-jar-with-dependencies.jar /app/bot.jar | ||
ENTRYPOINT ["java", "-jar", "/app/bot.jar"] | ||
CMD ["/app/config.properties"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,42 @@ | ||
# MailgramBot | ||
<img src="assets/snippet.png"> | ||
<img src="assets/snippet.png" alt="snippet.png"> | ||
|
||
[![Telegram](https://badgen.net/badge/icon/telegram?icon=telegram&label=open)](https://t.me/CoolMailgramBot) | ||
![Build status](https://github.com/WoodieDudy/MailgramBot/actions/workflows/test_and_pub.yml/badge.svg?branch=dev) | ||
|
||
### MailgramBot is a email client for Telegram | ||
|
||
Tasks: | ||
1. Implemented a conversation with the user in the console, configured the processing of incorrect commands and switching "states" (states) | ||
necessary to determine the currently available tools of the bot. | ||
2. States replaced by command classes for each command. Added base mail functional. | ||
3. Bot moved to Telegram (using Activity Bot) with buttons. Add Ci/CD. | ||
|
||
# About. | ||
Java-based Telegram bot that provides the functionality of receiving emails. | ||
If you want to know more about options you can use /help. | ||
|
||
## Clone the repo | ||
```sh | ||
$ git clone https://github.com/WoodieDudy/MailgramBot | ||
git clone https://github.com/WoodieDudy/MailgramBot | ||
cd MailgramBot | ||
``` | ||
|
||
### Running test with maven | ||
```sh | ||
$ mvn clean test | ||
mvn clean test | ||
``` | ||
|
||
### Running locally with maven | ||
```sh | ||
$ mvn clean compile exec:java | ||
# Build | ||
mvn -B clean package | ||
# Run | ||
java -jar target/mailgrambot-1.0-SNAPSHOT-jar-with-dependencies.jar src/main/resources/config.properties | ||
``` | ||
|
||
### Running with docker | ||
```sh | ||
docker build -t mailgrambot . | ||
docker run -it mailgrambot -v /path/to/config:/app/config.properties | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
package org.bot; | ||
|
||
import org.bot.application.Bot; | ||
import org.bot.domain.commands.AuthCommand; | ||
import org.bot.domain.commands.Command; | ||
import org.bot.domain.commands.HelpCommand; | ||
import org.bot.domain.commands.LettersListCommand; | ||
import org.bot.infrastructure.JakartaMailInterface; | ||
import org.bot.infrastructure.interfaces.BotInterface; | ||
import org.bot.application.BotLogic; | ||
import org.bot.infrastructure.ConsoleBotInterface; | ||
import org.bot.infrastructure.PropertyParser; | ||
import org.bot.infrastructure.interfaces.MailInterface; | ||
import org.telegram.telegrambots.meta.TelegramBotsApi; | ||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; | ||
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; | ||
|
||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
import java.time.Duration; | ||
|
||
public class App { | ||
public static void main(String[] args) { | ||
BotInterface botInterface = new ConsoleBotInterface(); | ||
public static void main(String[] args) throws IOException { | ||
MailInterface mailInterface = new JakartaMailInterface(); | ||
|
||
Command[] commands = createCommands(mailInterface); | ||
|
||
BotLogic botLogic = new BotLogic(commands); | ||
Bot bot = new Bot(botInterface, botLogic); | ||
bot.run(); | ||
} | ||
// src/main/resources/config.properties | ||
Properties properties = PropertyParser.parseProperties(args[0]); | ||
|
||
private static Command[] createCommands(MailInterface mailInterface) { // TODO: send messages in commands | ||
HelpCommand helpCommand = new HelpCommand(); | ||
Command[] commands = { | ||
new AuthCommand(mailInterface, Duration.ofDays(1)), | ||
new LettersListCommand(mailInterface), | ||
helpCommand | ||
}; | ||
helpCommand.generateHelpMessage(commands); | ||
return commands; | ||
Bot bot = new Bot( | ||
mailInterface, | ||
properties.getProperty("bot.token"), | ||
properties.getProperty("bot.name") | ||
); | ||
try { | ||
TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class); | ||
telegramBotsApi.registerBot(bot); | ||
} catch (TelegramApiException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
Oops, something went wrong.