github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/recipient.go (about) 1 // Copyright 2020 LINE Corporation 2 // 3 // LINE Corporation licenses this file to you under the Apache License, 4 // version 2.0 (the "License"); you may not use this file except in compliance 5 // with the License. You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package linebot 16 17 import "encoding/json" 18 19 // Recipient interface 20 type Recipient interface { 21 Recipient() 22 } 23 24 // AudienceObject type is created to be used with specific recipient objects 25 type AudienceObject struct { 26 Type string `json:"type"` 27 GroupID int `json:"audienceGroupId"` 28 } 29 30 // NewAudienceObject function 31 func NewAudienceObject(groupID int) *AudienceObject { 32 return &AudienceObject{ 33 Type: "audience", 34 GroupID: groupID, 35 } 36 } 37 38 // Recipient implements Recipient interface 39 func (*AudienceObject) Recipient() {} 40 41 // RedeliveryObject type is created to be used with specific recipient objects 42 type RedeliveryObject struct { 43 Type string `json:"type"` 44 RequestID string `json:"requestId"` 45 } 46 47 // NewRedeliveryObject function 48 func NewRedeliveryObject(requestID string) *RedeliveryObject { 49 return &RedeliveryObject{ 50 Type: "redelivery", 51 RequestID: requestID, 52 } 53 } 54 55 // Recipient implements Recipient interface 56 func (*RedeliveryObject) Recipient() {} 57 58 // RecipientOperator struct 59 type RecipientOperator struct { 60 ConditionAnd []Recipient `json:"and,omitempty"` 61 ConditionOr []Recipient `json:"or,omitempty"` 62 ConditionNot Recipient `json:"not,omitempty"` 63 } 64 65 // RecipientOperatorAnd method 66 func RecipientOperatorAnd(conditions ...Recipient) *RecipientOperator { 67 return &RecipientOperator{ 68 ConditionAnd: conditions, 69 } 70 } 71 72 // RecipientOperatorOr method 73 func RecipientOperatorOr(conditions ...Recipient) *RecipientOperator { 74 return &RecipientOperator{ 75 ConditionOr: conditions, 76 } 77 } 78 79 // RecipientOperatorNot method 80 func RecipientOperatorNot(condition Recipient) *RecipientOperator { 81 return &RecipientOperator{ 82 ConditionNot: condition, 83 } 84 } 85 86 // MarshalJSON method of Operator 87 func (o *RecipientOperator) MarshalJSON() ([]byte, error) { 88 return json.Marshal(&struct { 89 Type string `json:"type"` 90 ConditionAnd []Recipient `json:"and,omitempty"` 91 ConditionOr []Recipient `json:"or,omitempty"` 92 ConditionNot Recipient `json:"not,omitempty"` 93 }{ 94 Type: "operator", 95 ConditionAnd: o.ConditionAnd, 96 ConditionOr: o.ConditionOr, 97 ConditionNot: o.ConditionNot, 98 }) 99 } 100 101 // Recipient implements Recipient interface 102 func (*RecipientOperator) Recipient() {}