Add command to create WhatsApp group
This commit is contained in:
68
whatsapp-ext/group.go
Normal file
68
whatsapp-ext/group.go
Normal file
@ -0,0 +1,68 @@
|
||||
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
||||
// Copyright (C) 2019 Tulir Asokan
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package whatsappExt
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"maunium.net/go/mautrix-whatsapp/types"
|
||||
)
|
||||
|
||||
type CreateGroupResponse struct {
|
||||
Status int `json:"status"`
|
||||
GroupID types.WhatsAppID `json:"gid"`
|
||||
Participants map[types.WhatsAppID]struct {
|
||||
Code string `json:"code"`
|
||||
} `json:"participants"`
|
||||
|
||||
Source string `json:"-"`
|
||||
}
|
||||
|
||||
type actualCreateGroupResponse struct {
|
||||
Status int `json:"status"`
|
||||
GroupID types.WhatsAppID `json:"gid"`
|
||||
Participants []map[types.WhatsAppID]struct {
|
||||
Code string `json:"code"`
|
||||
} `json:"participants"`
|
||||
}
|
||||
|
||||
func (ext *ExtendedConn) CreateGroup(subject string, participants []types.WhatsAppID) (*CreateGroupResponse, error) {
|
||||
respChan, err := ext.Conn.CreateGroup(subject, participants)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var resp CreateGroupResponse
|
||||
var actualResp actualCreateGroupResponse
|
||||
resp.Source = <-respChan
|
||||
fmt.Println(">>>>>>", resp.Source)
|
||||
err = json.Unmarshal([]byte(resp.Source), &actualResp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.Status = actualResp.Status
|
||||
resp.GroupID = actualResp.GroupID
|
||||
resp.Participants = make(map[types.WhatsAppID]struct {
|
||||
Code string `json:"code"`
|
||||
})
|
||||
for _, participantMap := range actualResp.Participants {
|
||||
for jid, status := range participantMap {
|
||||
resp.Participants[jid] = status
|
||||
}
|
||||
}
|
||||
return &resp, nil
|
||||
}
|
@ -51,7 +51,6 @@ func (ext *ExtendedConn) AddHandler(handler whatsapp.Handler) {
|
||||
ext.handlers = append(ext.handlers, handler)
|
||||
}
|
||||
|
||||
|
||||
func (ext *ExtendedConn) RemoveHandler(handler whatsapp.Handler) bool {
|
||||
ext.Conn.RemoveHandler(handler)
|
||||
for i, v := range ext.handlers {
|
||||
@ -127,7 +126,7 @@ type ProfilePicInfo struct {
|
||||
URL string `json:"eurl"`
|
||||
Tag string `json:"tag"`
|
||||
|
||||
Status int16 `json:"status"`
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
func (ppi *ProfilePicInfo) Download() (io.ReadCloser, error) {
|
||||
|
Reference in New Issue
Block a user