From f1857d515c649accef810662eefcde7015f57182 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 22 Jul 2023 19:36:41 +0300 Subject: [PATCH] Expose RCS group creation in provisioning API --- provisioning.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/provisioning.go b/provisioning.go index ba642b5..b22d5d2 100644 --- a/provisioning.go +++ b/provisioning.go @@ -174,6 +174,9 @@ func (prov *ProvisioningAPI) ListContacts(w http.ResponseWriter, r *http.Request type StartChatRequest struct { Numbers []string `json:"numbers"` + + CreateRCSGroup bool `json:"create_rcs_group"` + RCSGroupName string `json:"rcs_group_name"` } type StartChatResponse struct { @@ -205,6 +208,10 @@ func (prov *ProvisioningAPI) StartChat(w http.ResponseWriter, r *http.Request) { Number2: number, }) } + if req.CreateRCSGroup { + reqData.CreateRCSGroup = proto.Bool(true) + reqData.RCSGroupName = proto.String(req.RCSGroupName) + } resp, err := user.Client.GetOrCreateConversation(&reqData) if err != nil { prov.zlog.Err(err).Msg("Failed to start chat") @@ -213,22 +220,18 @@ func (prov *ProvisioningAPI) StartChat(w http.ResponseWriter, r *http.Request) { ErrCode: "unknown error", }) return - } else if resp.GetStatus() == gmproto.GetOrCreateConversationResponse_CREATE_RCS { - prov.zlog.Debug().Msg("Creating RCS group") - // TODO this will always create a new group and won't deduplicate - reqData.CreateRCSGroup = proto.Bool(true) - resp, err = user.Client.GetOrCreateConversation(&reqData) - if err != nil { - prov.zlog.Err(err).Msg("Failed to start RCS chat") - jsonResponse(w, http.StatusInternalServerError, Error{ - Error: "Failed to start chat", - ErrCode: "unknown error", - }) - return - } + } else if len(req.Numbers) > 1 && resp.GetStatus() == gmproto.GetOrCreateConversationResponse_CREATE_RCS { + jsonResponse(w, http.StatusBadRequest, Error{ + Error: "All recipients are on RCS, please create a RCS group", + ErrCode: "rcs group", + }) + return } if resp.GetConversation() == nil { - prov.zlog.Warn().Str("status", resp.GetStatus().String()).Msg("No conversation in chat create response") + prov.zlog.Warn(). + Int("req_number_count", len(req.Numbers)). + Str("status", resp.GetStatus().String()). + Msg("No conversation in chat create response") jsonResponse(w, http.StatusInternalServerError, Error{ Error: "Failed to start chat", ErrCode: "unknown error",