@@ -98,7 +98,7 @@ func (c *HTTPClient) CreateDraft(ctx context.Context, grantID string, req *domai
9898
9999// buildDraftPayload builds the common payload for draft creation requests.
100100// This consolidates the repeated payload building logic across draft creation methods.
101- func buildDraftPayload (req * domain.CreateDraftRequest ) map [string ]any {
101+ func buildDraftPayload (req * domain.CreateDraftRequest , includeSignature bool ) map [string ]any {
102102 payload := map [string ]any {
103103 "subject" : req .Subject ,
104104 "body" : req .Body ,
@@ -118,6 +118,9 @@ func buildDraftPayload(req *domain.CreateDraftRequest) map[string]any {
118118 if req .ReplyToMsgID != "" {
119119 payload ["reply_to_message_id" ] = req .ReplyToMsgID
120120 }
121+ if includeSignature && req .SignatureID != "" {
122+ payload ["signature_id" ] = req .SignatureID
123+ }
121124 if len (req .Metadata ) > 0 {
122125 payload ["metadata" ] = req .Metadata
123126 }
@@ -128,7 +131,7 @@ func buildDraftPayload(req *domain.CreateDraftRequest) map[string]any {
128131func (c * HTTPClient ) createDraftWithJSON (ctx context.Context , grantID string , req * domain.CreateDraftRequest ) (* domain.Draft , error ) {
129132 queryURL := fmt .Sprintf ("%s/v3/grants/%s/drafts" , c .baseURL , grantID )
130133
131- resp , err := c .doJSONRequest (ctx , "POST" , queryURL , buildDraftPayload (req ))
134+ resp , err := c .doJSONRequest (ctx , "POST" , queryURL , buildDraftPayload (req , true ))
132135 if err != nil {
133136 return nil , err
134137 }
@@ -153,7 +156,7 @@ func (c *HTTPClient) createDraftWithMultipart(ctx context.Context, grantID strin
153156 writer := multipart .NewWriter (& buf )
154157
155158 // Add message as JSON field
156- messageJSON , err := json .Marshal (buildDraftPayload (req ))
159+ messageJSON , err := json .Marshal (buildDraftPayload (req , true ))
157160 if err != nil {
158161 return nil , fmt .Errorf ("failed to marshal message: %w" , err )
159162 }
@@ -221,7 +224,7 @@ func (c *HTTPClient) createDraftWithMultipart(ctx context.Context, grantID strin
221224// This is useful for large attachments or streaming file uploads.
222225func (c * HTTPClient ) CreateDraftWithAttachmentFromReader (ctx context.Context , grantID string , req * domain.CreateDraftRequest , filename string , contentType string , reader io.Reader ) (* domain.Draft , error ) {
223226 queryURL := fmt .Sprintf ("%s/v3/grants/%s/drafts" , c .baseURL , grantID )
224- payload := buildDraftPayload (req )
227+ payload := buildDraftPayload (req , true )
225228
226229 // Use pipe to stream multipart data
227230 pr , pw := io .Pipe ()
@@ -306,17 +309,26 @@ func (c *HTTPClient) DeleteDraft(ctx context.Context, grantID, draftID string) e
306309}
307310
308311// SendDraft sends a draft.
309- func (c * HTTPClient ) SendDraft (ctx context.Context , grantID , draftID string ) (* domain.Message , error ) {
312+ func (c * HTTPClient ) SendDraft (ctx context.Context , grantID , draftID string , req * domain. SendDraftRequest ) (* domain.Message , error ) {
310313 queryURL := fmt .Sprintf ("%s/v3/grants/%s/drafts/%s" , c .baseURL , grantID , draftID )
311314
312- req , err := http .NewRequestWithContext (ctx , "POST" , queryURL , nil )
315+ var bodyReader io.Reader
316+ if req != nil && req .SignatureID != "" {
317+ body , err := json .Marshal (map [string ]string {"signature_id" : req .SignatureID })
318+ if err != nil {
319+ return nil , fmt .Errorf ("failed to marshal send draft request: %w" , err )
320+ }
321+ bodyReader = bytes .NewReader (body )
322+ }
323+
324+ httpReq , err := http .NewRequestWithContext (ctx , "POST" , queryURL , bodyReader )
313325 if err != nil {
314326 return nil , err
315327 }
316- c .setAuthHeader (req )
317- req .Header .Set ("Content-Type" , "application/json" )
328+ c .setAuthHeader (httpReq )
329+ httpReq .Header .Set ("Content-Type" , "application/json" )
318330
319- resp , err := c .doRequest (ctx , req )
331+ resp , err := c .doRequest (ctx , httpReq )
320332 if err != nil {
321333 return nil , fmt .Errorf ("%w: %v" , domain .ErrNetworkError , err )
322334 }
0 commit comments