github.com/line/line-bot-sdk-go/v7@v7.21.0/linebot/quick_reply.go (about)

     1  // Copyright 2018 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 (
    18  	"encoding/json"
    19  )
    20  
    21  // QuickReplyItems struct
    22  type QuickReplyItems struct {
    23  	Items []*QuickReplyButton `json:"items"`
    24  }
    25  
    26  // NewQuickReplyItems function
    27  func NewQuickReplyItems(buttons ...*QuickReplyButton) *QuickReplyItems {
    28  	return &QuickReplyItems{
    29  		Items: buttons,
    30  	}
    31  }
    32  
    33  // QuickReplyButton type
    34  type QuickReplyButton struct {
    35  	ImageURL string
    36  	Action   QuickReplyAction
    37  }
    38  
    39  // MarshalJSON method of QuickReplyButton
    40  func (b *QuickReplyButton) MarshalJSON() ([]byte, error) {
    41  	return json.Marshal(&struct {
    42  		Type     string           `json:"type"`
    43  		ImageURL string           `json:"imageUrl,omitempty"`
    44  		Action   QuickReplyAction `json:"action"`
    45  	}{
    46  		Type:     "action",
    47  		ImageURL: b.ImageURL,
    48  		Action:   b.Action,
    49  	})
    50  }
    51  
    52  // NewQuickReplyButton function
    53  func NewQuickReplyButton(imageURL string, action QuickReplyAction) *QuickReplyButton {
    54  	return &QuickReplyButton{
    55  		ImageURL: imageURL,
    56  		Action:   action,
    57  	}
    58  }