Browse Source

feat: Add Join Group with Link (#66)

* Add possibility to join a group with a link

* Review changes

- Add new link in readme
- Change link to adhere to style of project
- Remove logging
pull/67/head v4.6.0
Tim Vandecasteele 3 years ago
committed by GitHub
parent
commit
e495bf8435
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      readme.md
  2. 2
      src/cmd/root.go
  3. 15
      src/domains/group/group.go
  4. 33
      src/internal/rest/group.go
  5. 30
      src/services/group.go

1
readme.md

@ -111,6 +111,7 @@ API using [openapi-generator](https://openapi-generator.tech/#try)
| ✅ | Send Location | POST | /send/location |
| ✅ | Revoke Message | POST | /message/:message_id/revoke |
| ✅ | React Message | POST | /message/:message_id/react |
| ✅ | Join Group With Link | POST | /group/join-with-link" |
```
✅ = Available

2
src/cmd/root.go

@ -99,12 +99,14 @@ func runRest(_ *cobra.Command, _ []string) {
sendService := services.NewSendService(cli)
userService := services.NewUserService(cli)
messageService := services.NewMessageService(cli)
groupService := services.NewGroupService(cli)
// Rest
rest.InitRestApp(app, appService)
rest.InitRestSend(app, sendService)
rest.InitRestUser(app, userService)
rest.InitRestMessage(app, messageService)
rest.InitRestGroup(app, groupService)
app.Get("/", func(c *fiber.Ctx) error {
return c.Render("index", fiber.Map{

15
src/domains/group/group.go

@ -0,0 +1,15 @@
package group
import "context"
type IGroupService interface {
JoinGroupWithLink(ctx context.Context, request JoinGroupWithLinkRequest) (response JoinGroupWithLinkResponse, err error)
}
type JoinGroupWithLinkRequest struct {
Link string `json:"link" query:"link"`
}
type JoinGroupWithLinkResponse struct {
JID string `json:"jid"`
}

33
src/internal/rest/group.go

@ -0,0 +1,33 @@
package rest
import (
domainGroup "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/group"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/utils"
"github.com/gofiber/fiber/v2"
)
type Group struct {
Service domainGroup.IGroupService
}
func InitRestGroup(app *fiber.App, service domainGroup.IGroupService) Group {
rest := Group{Service: service}
app.Post("/group/join-with-link", rest.JoinGroupWithLink)
return rest
}
func (controller *Group) JoinGroupWithLink(c *fiber.Ctx) error {
var request domainGroup.JoinGroupWithLinkRequest
err := c.BodyParser(&request)
utils.PanicIfNeeded(err)
response, err := controller.Service.JoinGroupWithLink(c.UserContext(), request)
utils.PanicIfNeeded(err)
return c.JSON(utils.ResponseData{
Status: 200,
Code: "SUCCESS",
Message: "Success joined group",
Results: response,
})
}

30
src/services/group.go

@ -0,0 +1,30 @@
package services
import (
"context"
domainGroup "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/group"
"github.com/aldinokemal/go-whatsapp-web-multidevice/pkg/whatsapp"
"go.mau.fi/whatsmeow"
)
type groupService struct {
WaCli *whatsmeow.Client
}
func NewGroupService(waCli *whatsmeow.Client) domainGroup.IGroupService {
return &groupService{
WaCli: waCli,
}
}
func (service groupService) JoinGroupWithLink(_ context.Context, request domainGroup.JoinGroupWithLinkRequest) (response domainGroup.JoinGroupWithLinkResponse, err error) {
whatsapp.MustLogin(service.WaCli)
jid, err := service.WaCli.JoinGroupWithLink(request.Link)
if err != nil {
return
}
response.JID = jid.String()
return response, nil
}
Loading…
Cancel
Save