Skip to content

Commit 5496f8f

Browse files
committed
Update dependencies and enhance Telegram integration
- Added `rustls` as a dependency for improved TLS support. - Updated `Cargo.lock` to reflect the new `rustls` version. - Modified the API to include a new optional `telegram_token` in `PlatformCredentials`. - Enhanced the `create_binding` function to handle Telegram token and messaging configuration. - Installed the default crypto provider for `rustls` in the main function.
1 parent 72c5b15 commit 5496f8f

File tree

5 files changed

+53
-64
lines changed

5 files changed

+53
-64
lines changed

.github/workflows/release.yml

Lines changed: 12 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@ env:
1616

1717
jobs:
1818
build-and-push:
19-
runs-on: ${{ matrix.runner }}
20-
strategy:
21-
fail-fast: false
22-
matrix:
23-
include:
24-
- arch: amd64
25-
runner: ubuntu-latest
26-
- arch: arm64
27-
runner: ubuntu-24.04-arm
19+
runs-on: ubuntu-latest
2820
permissions:
2921
contents: write
3022
packages: write
@@ -60,68 +52,24 @@ jobs:
6052
context: .
6153
target: slim
6254
push: true
63-
platforms: linux/${{ matrix.arch }}
6455
tags: |
65-
66-
${{ env.IMAGE }}:${{ steps.version.outputs.version }}-slim-${{ matrix.arch }}
67-
${{ env.IMAGE }}:slim-${{ matrix.arch }}
68-
cache-from: type=gha,scope=release-slim
69-
cache-to: type=gha,mode=max,scope=release-slim
56+
${{ env.IMAGE }}:${{ steps.version.outputs.version }}-slim
57+
${{ env.IMAGE }}:slim
58+
cache-from: type=gha
59+
cache-to: type=gha,mode=max
7060

7161
- name: Build and push full
7262
uses: docker/build-push-action@v6
7363
with:
7464
context: .
7565
target: full
7666
push: true
77-
platforms: linux/${{ matrix.arch }}
7867
tags: |
79-
${{ env.IMAGE }}:${{ steps.version.outputs.version }}-full-${{ matrix.arch }}
80-
${{ env.IMAGE }}:full-${{ matrix.arch }}
81-
cache-from: type=gha,scope=release-full
82-
cache-to: type=gha,mode=max,scope=release-full
83-
84-
85-
publish-manifests:
86-
runs-on: ubuntu-latest
87-
needs: build-and-push
88-
permissions:
89-
contents: write
90-
packages: write
91-
steps:
92-
- name: Determine version tag
93-
id: version
94-
run: |
95-
if [ -n "${{ github.event.inputs.tag }}" ]; then
96-
VERSION="${{ github.event.inputs.tag }}"
97-
elif [[ "$GITHUB_REF" == refs/tags/v* ]]; then
98-
VERSION="${GITHUB_REF#refs/tags/}"
99-
else
100-
VERSION="dev-$(echo $GITHUB_SHA | head -c 7)"
101-
fi
102-
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
103-
104-
- name: Log in to GHCR
105-
uses: docker/login-action@v3
106-
with:
107-
registry: ${{ env.REGISTRY }}
108-
username: ${{ github.actor }}
109-
password: ${{ secrets.GITHUB_TOKEN }}
110-
111-
- name: Create multi-arch manifests
112-
run: |
113-
VERSION="${{ steps.version.outputs.version }}"
114-
docker buildx imagetools create \
115-
--tag ${{ env.IMAGE }}:${VERSION}-slim \
116-
--tag ${{ env.IMAGE }}:slim \
117-
${{ env.IMAGE }}:${VERSION}-slim-amd64 \
118-
${{ env.IMAGE }}:${VERSION}-slim-arm64
119-
docker buildx imagetools create \
120-
--tag ${{ env.IMAGE }}:${VERSION}-full \
121-
--tag ${{ env.IMAGE }}:full \
122-
--tag ${{ env.IMAGE }}:latest \
123-
${{ env.IMAGE }}:${VERSION}-full-amd64 \
124-
${{ env.IMAGE }}:${VERSION}-full-arm64
68+
${{ env.IMAGE }}:${{ steps.version.outputs.version }}-full
69+
${{ env.IMAGE }}:full
70+
${{ env.IMAGE }}:latest
71+
cache-from: type=gha
72+
cache-to: type=gha,mode=max
12573

12674
- name: Log in to Fly registry
12775
uses: docker/login-action@v3
@@ -132,9 +80,8 @@ jobs:
13280

13381
- name: Push to Fly registry
13482
run: |
135-
VERSION="${{ steps.version.outputs.version }}"
13683
docker buildx imagetools create \
137-
--tag registry.fly.io/spacebot-image:${VERSION} \
84+
--tag registry.fly.io/spacebot-image:${{ steps.version.outputs.version }} \
13885
--tag registry.fly.io/spacebot-image:latest \
13986
${{ env.IMAGE }}:latest
14087
@@ -152,3 +99,4 @@ jobs:
15299
with:
153100
tag_name: ${{ steps.version.outputs.version }}
154101
generate_release_notes: true
102+

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ async-trait = "0.1"
8282
# Slack
8383
slack-morphism = { version = "2.17", features = ["hyper"] }
8484

85+
# TLS (shared crypto backend for slack-morphism, reqwest, teloxide)
86+
rustls = { version = "0.23", default-features = false, features = ["ring"] }
87+
8588
# Telegram
8689
teloxide = { version = "0.17", default-features = false, features = ["rustls"] }
8790

src/api/server.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,6 +3357,9 @@ struct PlatformCredentials {
33573357
/// Slack app token.
33583358
#[serde(default)]
33593359
slack_app_token: Option<String>,
3360+
/// Telegram bot token.
3361+
#[serde(default)]
3362+
telegram_token: Option<String>,
33603363
}
33613364

33623365
#[derive(Serialize)]
@@ -3394,6 +3397,7 @@ async fn create_binding(
33943397
// Track adapters that need to be started at runtime
33953398
let mut new_discord_token: Option<String> = None;
33963399
let mut new_slack_tokens: Option<(String, String)> = None;
3400+
let mut new_telegram_token: Option<String> = None;
33973401

33983402
// Write platform credentials if provided
33993403
if let Some(credentials) = &request.platform_credentials {
@@ -3429,6 +3433,21 @@ async fn create_binding(
34293433
new_slack_tokens = Some((bot_token.clone(), app_token.to_string()));
34303434
}
34313435
}
3436+
if let Some(token) = &credentials.telegram_token {
3437+
if !token.is_empty() {
3438+
if doc.get("messaging").is_none() {
3439+
doc["messaging"] = toml_edit::Item::Table(toml_edit::Table::new());
3440+
}
3441+
let messaging = doc["messaging"].as_table_mut().ok_or(StatusCode::INTERNAL_SERVER_ERROR)?;
3442+
if !messaging.contains_key("telegram") {
3443+
messaging["telegram"] = toml_edit::Item::Table(toml_edit::Table::new());
3444+
}
3445+
let telegram = messaging["telegram"].as_table_mut().ok_or(StatusCode::INTERNAL_SERVER_ERROR)?;
3446+
telegram["enabled"] = toml_edit::value(true);
3447+
telegram["token"] = toml_edit::value(token.as_str());
3448+
new_telegram_token = Some(token.clone());
3449+
}
3450+
}
34323451
}
34333452

34343453
// Add the binding to the [[bindings]] array
@@ -3558,6 +3577,20 @@ async fn create_binding(
35583577
tracing::error!(%error, "failed to hot-start slack adapter");
35593578
}
35603579
}
3580+
3581+
if let Some(token) = new_telegram_token {
3582+
let telegram_perms = {
3583+
let perms = crate::config::TelegramPermissions::from_config(
3584+
new_config.messaging.telegram.as_ref().expect("telegram config exists when token is provided"),
3585+
&new_config.bindings,
3586+
);
3587+
std::sync::Arc::new(arc_swap::ArcSwap::from_pointee(perms))
3588+
};
3589+
let adapter = crate::messaging::telegram::TelegramAdapter::new(&token, telegram_perms);
3590+
if let Err(error) = manager.register_and_start(adapter).await {
3591+
tracing::error!(%error, "failed to hot-start telegram adapter");
3592+
}
3593+
}
35613594
}
35623595
}
35633596

src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ struct ActiveChannel {
5353
}
5454

5555
fn main() -> anyhow::Result<()> {
56+
rustls::crypto::ring::default_provider()
57+
.install_default()
58+
.expect("failed to install rustls crypto provider");
59+
5660
let cli = Cli::parse();
5761
let command = cli.command.unwrap_or(Command::Start { foreground: false });
5862

0 commit comments

Comments
 (0)