Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to join group using invite link #601

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RUN dpkg-reconfigure debconf --frontend=noninteractive \
&& apt-get -qqy install --no-install-recommends \
wget software-properties-common git locales zip unzip \
file build-essential libz-dev zlib1g-dev < /dev/null > /dev/null \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
Expand All @@ -45,7 +45,7 @@ ENV JAVA_OPTS="-Djdk.lang.Process.launchMechanism=vfork"
ENV LANG en_US.UTF-8

RUN cd /tmp/ \
&& git clone https://github.com/swaggo/swag.git swag-${SWAG_VERSION} \
&& git clone https://github.com/swaggo/swag.git swag-${SWAG_VERSION} \
&& cd swag-${SWAG_VERSION} \
&& git checkout -q v${SWAG_VERSION} \
&& make -s < /dev/null > /dev/null \
Expand Down Expand Up @@ -141,7 +141,7 @@ COPY src/go.sum /tmp/signal-cli-rest-api-src/
RUN cd /tmp/signal-cli-rest-api-src && swag init && go test ./client -v && go build

# build supervisorctl_config_creator
RUN cd /tmp/signal-cli-rest-api-src/scripts && go build -o jsonrpc2-helper
RUN cd /tmp/signal-cli-rest-api-src/scripts && go build -o jsonrpc2-helper

# Start a fresh container for release container

Expand All @@ -163,7 +163,7 @@ ENV BUILD_VERSION=$BUILD_VERSION_ARG
RUN dpkg-reconfigure debconf --frontend=noninteractive \
&& apt-get -qq update \
&& apt-get -qq install -y --no-install-recommends util-linux supervisor netcat openjdk-21-jre curl < /dev/null > /dev/null \
&& rm -rf /var/lib/apt/lists/*
&& rm -rf /var/lib/apt/lists/*

COPY --from=buildcontainer /tmp/signal-cli-rest-api-src/signal-cli-rest-api /usr/bin/signal-cli-rest-api
COPY --from=buildcontainer /opt/signal-cli-${SIGNAL_CLI_VERSION} /opt/signal-cli-${SIGNAL_CLI_VERSION}
Expand Down
54 changes: 54 additions & 0 deletions src/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,60 @@ func (a *Api) JoinGroup(c *gin.Context) {
c.Status(http.StatusNoContent)
}

// @Summary Join a Signal Group by invite link.
// @Tags Groups
// @Description Join the specified Signal Group by invite link.
// @Accept json
// @Produce json
// @Success 204 {string} OK
// @Failure 400 {object} Error
// @Param number path string true "Registered Phone Number"
// @Query invite_link query string true "Invite Link"
// @Router /v1/groups/{number}/join_by_invite_link [post]
func (a *Api) JoinGroupByInviteLink(c *gin.Context) {
number := c.Param("number")
if number == "" {
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
return
}

inviteLink := c.Query("invite_link")
err := a.signalClient.JoinGroupByInviteLink(number, inviteLink)
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}

c.Status(http.StatusNoContent)
}

// @Summary Get a Signal Group info by invite link.
// @Tags Groups
// @Description Get the specified Signal Group info by invite link.
// @Accept json
// @Produce json
// @Success 200 {string} OK
// @Failure 400 {object} Error
// @Param number path string true "Registered Phone Number"
// @Query invite_link query string true "Invite Link"
// @Router /v1/groups/{number}/join_info_by_invite_link [get]
func (a *Api) GetJoinGroupInfoByInviteLink(c *gin.Context) {
number := c.Param("number")
if number == "" {
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
return
}

inviteLink := c.Query("invite_link")
jsonStr, err := a.signalClient.GetJoinGroupInfoByInviteLink(number, inviteLink)
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}

c.String(200, jsonStr)
}

// @Summary Quit a Signal Group.
// @Tags Groups
// @Description Quit the specified Signal Group.
Expand Down
29 changes: 28 additions & 1 deletion src/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"encoding/json"
"errors"
"fmt"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"

log "github.com/sirupsen/logrus"

securejoin "github.com/cyphar/filepath-securejoin"
"github.com/h2non/filetype"

Expand Down Expand Up @@ -1559,6 +1560,32 @@ func (s *SignalClient) JoinGroup(number string, groupId string) error {
return err
}

func (s *SignalClient) JoinGroupByInviteLink(number string, inviteLink string) error {
var err error
if s.signalCliMode == JsonRpc {
type Request struct {
InviteLink string `json:"uri"`
}
request := Request{InviteLink: inviteLink}
jsonRpc2Client, err := s.getJsonRpc2Client()
if err != nil {
return err
}
_, err = jsonRpc2Client.getRaw("joinGroup", &number, request)
} else {
_, err = s.cliClient.Execute(true, []string{"--config", s.signalCliConfig, "-a", number, "joinGroup", "--uri", inviteLink}, "")
}
return err
}

func (s *SignalClient) GetJoinGroupInfoByInviteLink(number string, inviteLink string) (string, error) {
if s.signalCliMode == JsonRpc {
return "", errors.New("Not implemented")
}

return s.cliClient.Execute(true, []string{"--config", s.signalCliConfig, "--output", "json", "-a", number, "getJoinGroupInfo", "--uri", inviteLink}, "")
}

func (s *SignalClient) QuitGroup(number string, groupId string) error {
var err error
if s.signalCliMode == JsonRpc {
Expand Down
11 changes: 7 additions & 4 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ package main
import (
"encoding/json"
"flag"
"io/ioutil"
"net/http"
"os"
"strconv"

"github.com/bbernhard/signal-cli-rest-api/api"
"github.com/bbernhard/signal-cli-rest-api/client"
docs "github.com/bbernhard/signal-cli-rest-api/docs"
Expand All @@ -12,10 +17,6 @@ import (
log "github.com/sirupsen/logrus"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"io/ioutil"
"net/http"
"os"
"strconv"
)

// @title Signal Cli REST API
Expand Down Expand Up @@ -193,6 +194,8 @@ func main() {
{
groups.POST(":number", api.CreateGroup)
groups.GET(":number", api.GetGroups)
groups.POST(":number/join_by_invite_link", api.JoinGroupByInviteLink)
groups.GET(":number/join_info_by_invite_link", api.GetJoinGroupInfoByInviteLink)
groups.GET(":number/:groupid", api.GetGroup)
groups.DELETE(":number/:groupid", api.DeleteGroup)
groups.POST(":number/:groupid/block", api.BlockGroup)
Expand Down