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

     1  // Copyright 2016 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  	"bytes"
    19  	"context"
    20  	"encoding/json"
    21  	"fmt"
    22  	"io"
    23  	"net/http"
    24  	"os"
    25  )
    26  
    27  // RichMenuActionType type
    28  type RichMenuActionType string
    29  
    30  // RichMenuActionType constants
    31  const (
    32  	RichMenuActionTypeURI            RichMenuActionType = "uri"
    33  	RichMenuActionTypeMessage        RichMenuActionType = "message"
    34  	RichMenuActionTypePostback       RichMenuActionType = "postback"
    35  	RichMenuActionTypeDatetimePicker RichMenuActionType = "datetimepicker"
    36  	RichMenuActionTypeRichMenuSwitch RichMenuActionType = "richmenuswitch"
    37  )
    38  
    39  // RichMenuSize type
    40  type RichMenuSize struct {
    41  	Width  int `json:"width"`
    42  	Height int `json:"height"`
    43  }
    44  
    45  // RichMenuBounds type
    46  type RichMenuBounds struct {
    47  	X      int `json:"x"`
    48  	Y      int `json:"y"`
    49  	Width  int `json:"width"`
    50  	Height int `json:"height"`
    51  }
    52  
    53  // RichMenuAction with type
    54  type RichMenuAction struct {
    55  	Type            RichMenuActionType `json:"type"`
    56  	URI             string             `json:"uri,omitempty"`
    57  	Text            string             `json:"text,omitempty"`
    58  	DisplayText     string             `json:"displayText,omitempty"`
    59  	Label           string             `json:"label,omitempty"`
    60  	Data            string             `json:"data,omitempty"`
    61  	Mode            string             `json:"mode,omitempty"`
    62  	Initial         string             `json:"initial,omitempty"`
    63  	Max             string             `json:"max,omitempty"`
    64  	Min             string             `json:"min,omitempty"`
    65  	RichMenuAliasID string             `json:"richMenuAliasId,omitempty"`
    66  	InputOption     InputOption        `json:"inputOption,omitempty"`
    67  	FillInText      string             `json:"fillInText,omitempty"`
    68  }
    69  
    70  // AreaDetail type for areas array
    71  type AreaDetail struct {
    72  	Bounds RichMenuBounds `json:"bounds"`
    73  	Action RichMenuAction `json:"action"`
    74  }
    75  
    76  // RichMenu type
    77  type RichMenu struct {
    78  	Size        RichMenuSize
    79  	Selected    bool
    80  	Name        string
    81  	ChatBarText string
    82  	Areas       []AreaDetail
    83  }
    84  
    85  /*
    86  {
    87    "richmenus": [
    88      {
    89        "richMenuId": "{richMenuId}",
    90        "size": {
    91          "width": 2500,
    92          "height": 1686
    93        },
    94        "selected": false,
    95        "areas": [
    96          {
    97            "bounds": {
    98              "x": 0,
    99              "y": 0,
   100              "width": 2500,
   101              "height": 1686
   102            },
   103            "action": {
   104              "type": "postback",
   105              "data": "action=buy&itemid=123",
   106              "label":"Buy",
   107              "displayText":"Buy"
   108            }
   109          }
   110        ]
   111      }
   112    ]
   113  }
   114  */
   115  
   116  // GetRichMenu method
   117  func (client *Client) GetRichMenu(richMenuID string) *GetRichMenuCall {
   118  	return &GetRichMenuCall{
   119  		c:          client,
   120  		richMenuID: richMenuID,
   121  	}
   122  }
   123  
   124  // GetRichMenuCall type
   125  type GetRichMenuCall struct {
   126  	c   *Client
   127  	ctx context.Context
   128  
   129  	richMenuID string
   130  }
   131  
   132  // WithContext method
   133  func (call *GetRichMenuCall) WithContext(ctx context.Context) *GetRichMenuCall {
   134  	call.ctx = ctx
   135  	return call
   136  }
   137  
   138  // Do method
   139  func (call *GetRichMenuCall) Do() (*RichMenuResponse, error) {
   140  	endpoint := fmt.Sprintf(APIEndpointGetRichMenu, call.richMenuID)
   141  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil)
   142  	if err != nil {
   143  		return nil, err
   144  	}
   145  	defer closeResponse(res)
   146  	return decodeToRichMenuResponse(res)
   147  }
   148  
   149  // GetUserRichMenu method
   150  func (client *Client) GetUserRichMenu(userID string) *GetUserRichMenuCall {
   151  	return &GetUserRichMenuCall{
   152  		c:      client,
   153  		userID: userID,
   154  	}
   155  }
   156  
   157  // GetUserRichMenuCall type
   158  type GetUserRichMenuCall struct {
   159  	c   *Client
   160  	ctx context.Context
   161  
   162  	userID string
   163  }
   164  
   165  // WithContext method
   166  func (call *GetUserRichMenuCall) WithContext(ctx context.Context) *GetUserRichMenuCall {
   167  	call.ctx = ctx
   168  	return call
   169  }
   170  
   171  // Do method
   172  func (call *GetUserRichMenuCall) Do() (*RichMenuResponse, error) {
   173  	endpoint := fmt.Sprintf(APIEndpointGetUserRichMenu, call.userID)
   174  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil)
   175  	if err != nil {
   176  		return nil, err
   177  	}
   178  	defer closeResponse(res)
   179  	return decodeToRichMenuResponse(res)
   180  }
   181  
   182  // CreateRichMenu method
   183  func (client *Client) CreateRichMenu(richMenu RichMenu) *CreateRichMenuCall {
   184  	return &CreateRichMenuCall{
   185  		c:        client,
   186  		richMenu: richMenu,
   187  	}
   188  }
   189  
   190  // CreateRichMenuCall type
   191  type CreateRichMenuCall struct {
   192  	c   *Client
   193  	ctx context.Context
   194  
   195  	richMenu RichMenu
   196  }
   197  
   198  // WithContext method
   199  func (call *CreateRichMenuCall) WithContext(ctx context.Context) *CreateRichMenuCall {
   200  	call.ctx = ctx
   201  	return call
   202  }
   203  
   204  func (call *CreateRichMenuCall) encodeJSON(w io.Writer) error {
   205  	enc := json.NewEncoder(w)
   206  	return enc.Encode(&struct {
   207  		Size        RichMenuSize `json:"size"`
   208  		Selected    bool         `json:"selected"`
   209  		Name        string       `json:"name"`
   210  		ChatBarText string       `json:"chatBarText"`
   211  		Areas       []AreaDetail `json:"areas"`
   212  	}{
   213  		Size:        call.richMenu.Size,
   214  		Selected:    call.richMenu.Selected,
   215  		Name:        call.richMenu.Name,
   216  		ChatBarText: call.richMenu.ChatBarText,
   217  		Areas:       call.richMenu.Areas,
   218  	})
   219  }
   220  
   221  // Do method
   222  func (call *CreateRichMenuCall) Do() (*RichMenuIDResponse, error) {
   223  	var buf bytes.Buffer
   224  	if err := call.encodeJSON(&buf); err != nil {
   225  		return nil, err
   226  	}
   227  	res, err := call.c.post(call.ctx, APIEndpointCreateRichMenu, &buf)
   228  	if err != nil {
   229  		return nil, err
   230  	}
   231  	defer closeResponse(res)
   232  	return decodeToRichMenuIDResponse(res)
   233  }
   234  
   235  // DeleteRichMenu method
   236  func (client *Client) DeleteRichMenu(richMenuID string) *DeleteRichMenuCall {
   237  	return &DeleteRichMenuCall{
   238  		c:          client,
   239  		richMenuID: richMenuID,
   240  	}
   241  }
   242  
   243  // DeleteRichMenuCall type
   244  type DeleteRichMenuCall struct {
   245  	c   *Client
   246  	ctx context.Context
   247  
   248  	richMenuID string
   249  }
   250  
   251  // WithContext method
   252  func (call *DeleteRichMenuCall) WithContext(ctx context.Context) *DeleteRichMenuCall {
   253  	call.ctx = ctx
   254  	return call
   255  }
   256  
   257  // Do method
   258  func (call *DeleteRichMenuCall) Do() (*BasicResponse, error) {
   259  	endpoint := fmt.Sprintf(APIEndpointDeleteRichMenu, call.richMenuID)
   260  	res, err := call.c.delete(call.ctx, endpoint)
   261  	if err != nil {
   262  		return nil, err
   263  	}
   264  	defer closeResponse(res)
   265  	return decodeToBasicResponse(res)
   266  }
   267  
   268  // LinkUserRichMenu method
   269  func (client *Client) LinkUserRichMenu(userID, richMenuID string) *LinkUserRichMenuCall {
   270  	return &LinkUserRichMenuCall{
   271  		c:          client,
   272  		userID:     userID,
   273  		richMenuID: richMenuID,
   274  	}
   275  }
   276  
   277  // LinkUserRichMenuCall type
   278  type LinkUserRichMenuCall struct {
   279  	c   *Client
   280  	ctx context.Context
   281  
   282  	userID     string
   283  	richMenuID string
   284  }
   285  
   286  // WithContext method
   287  func (call *LinkUserRichMenuCall) WithContext(ctx context.Context) *LinkUserRichMenuCall {
   288  	call.ctx = ctx
   289  	return call
   290  }
   291  
   292  // Do method
   293  func (call *LinkUserRichMenuCall) Do() (*BasicResponse, error) {
   294  	endpoint := fmt.Sprintf(APIEndpointLinkUserRichMenu, call.userID, call.richMenuID)
   295  	res, err := call.c.post(call.ctx, endpoint, nil)
   296  	if err != nil {
   297  		return nil, err
   298  	}
   299  	defer closeResponse(res)
   300  	return decodeToBasicResponse(res)
   301  }
   302  
   303  // UnlinkUserRichMenu method
   304  func (client *Client) UnlinkUserRichMenu(userID string) *UnlinkUserRichMenuCall {
   305  	return &UnlinkUserRichMenuCall{
   306  		c:      client,
   307  		userID: userID,
   308  	}
   309  }
   310  
   311  // UnlinkUserRichMenuCall type
   312  type UnlinkUserRichMenuCall struct {
   313  	c   *Client
   314  	ctx context.Context
   315  
   316  	userID string
   317  }
   318  
   319  // WithContext method
   320  func (call *UnlinkUserRichMenuCall) WithContext(ctx context.Context) *UnlinkUserRichMenuCall {
   321  	call.ctx = ctx
   322  	return call
   323  }
   324  
   325  // Do method
   326  func (call *UnlinkUserRichMenuCall) Do() (*BasicResponse, error) {
   327  	endpoint := fmt.Sprintf(APIEndpointUnlinkUserRichMenu, call.userID)
   328  	res, err := call.c.delete(call.ctx, endpoint)
   329  	if err != nil {
   330  		return nil, err
   331  	}
   332  	defer closeResponse(res)
   333  	return decodeToBasicResponse(res)
   334  }
   335  
   336  // SetDefaultRichMenu method
   337  func (client *Client) SetDefaultRichMenu(richMenuID string) *SetDefaultRichMenuCall {
   338  	return &SetDefaultRichMenuCall{
   339  		c:          client,
   340  		richMenuID: richMenuID,
   341  	}
   342  }
   343  
   344  // SetDefaultRichMenuCall type
   345  type SetDefaultRichMenuCall struct {
   346  	c   *Client
   347  	ctx context.Context
   348  
   349  	richMenuID string
   350  }
   351  
   352  // WithContext method
   353  func (call *SetDefaultRichMenuCall) WithContext(ctx context.Context) *SetDefaultRichMenuCall {
   354  	call.ctx = ctx
   355  	return call
   356  }
   357  
   358  // Do method
   359  func (call *SetDefaultRichMenuCall) Do() (*BasicResponse, error) {
   360  	endpoint := fmt.Sprintf(APIEndpointSetDefaultRichMenu, call.richMenuID)
   361  	res, err := call.c.post(call.ctx, endpoint, nil)
   362  	if err != nil {
   363  		return nil, err
   364  	}
   365  	defer closeResponse(res)
   366  	return decodeToBasicResponse(res)
   367  }
   368  
   369  // CancelDefaultRichMenu method
   370  func (client *Client) CancelDefaultRichMenu() *CancelDefaultRichMenuCall {
   371  	return &CancelDefaultRichMenuCall{
   372  		c: client,
   373  	}
   374  }
   375  
   376  // CancelDefaultRichMenuCall type
   377  type CancelDefaultRichMenuCall struct {
   378  	c   *Client
   379  	ctx context.Context
   380  }
   381  
   382  // WithContext method
   383  func (call *CancelDefaultRichMenuCall) WithContext(ctx context.Context) *CancelDefaultRichMenuCall {
   384  	call.ctx = ctx
   385  	return call
   386  }
   387  
   388  // Do method
   389  func (call *CancelDefaultRichMenuCall) Do() (*BasicResponse, error) {
   390  	res, err := call.c.delete(call.ctx, APIEndpointDefaultRichMenu)
   391  	if err != nil {
   392  		return nil, err
   393  	}
   394  	defer closeResponse(res)
   395  	return decodeToBasicResponse(res)
   396  }
   397  
   398  // GetDefaultRichMenu method
   399  func (client *Client) GetDefaultRichMenu() *GetDefaultRichMenuCall {
   400  	return &GetDefaultRichMenuCall{
   401  		c: client,
   402  	}
   403  }
   404  
   405  // GetDefaultRichMenuCall type
   406  type GetDefaultRichMenuCall struct {
   407  	c   *Client
   408  	ctx context.Context
   409  }
   410  
   411  // WithContext method
   412  func (call *GetDefaultRichMenuCall) WithContext(ctx context.Context) *GetDefaultRichMenuCall {
   413  	call.ctx = ctx
   414  	return call
   415  }
   416  
   417  // Do method
   418  func (call *GetDefaultRichMenuCall) Do() (*RichMenuIDResponse, error) {
   419  	res, err := call.c.get(call.ctx, call.c.endpointBase, APIEndpointDefaultRichMenu, nil)
   420  	if err != nil {
   421  		return nil, err
   422  	}
   423  	defer closeResponse(res)
   424  	return decodeToRichMenuIDResponse(res)
   425  }
   426  
   427  // GetRichMenuList method
   428  func (client *Client) GetRichMenuList() *GetRichMenuListCall {
   429  	return &GetRichMenuListCall{
   430  		c: client,
   431  	}
   432  }
   433  
   434  // GetRichMenuListCall type
   435  type GetRichMenuListCall struct {
   436  	c   *Client
   437  	ctx context.Context
   438  }
   439  
   440  // WithContext method
   441  func (call *GetRichMenuListCall) WithContext(ctx context.Context) *GetRichMenuListCall {
   442  	call.ctx = ctx
   443  	return call
   444  }
   445  
   446  // Do method
   447  func (call *GetRichMenuListCall) Do() ([]*RichMenuResponse, error) {
   448  	res, err := call.c.get(call.ctx, call.c.endpointBase, APIEndpointListRichMenu, nil)
   449  	if err != nil {
   450  		return nil, err
   451  	}
   452  	defer closeResponse(res)
   453  	return decodeToRichMenuListResponse(res)
   454  }
   455  
   456  // DownloadRichMenuImage method
   457  func (client *Client) DownloadRichMenuImage(richMenuID string) *DownloadRichMenuImageCall {
   458  	return &DownloadRichMenuImageCall{
   459  		c:          client,
   460  		richMenuID: richMenuID,
   461  	}
   462  }
   463  
   464  // DownloadRichMenuImageCall type
   465  type DownloadRichMenuImageCall struct {
   466  	c   *Client
   467  	ctx context.Context
   468  
   469  	richMenuID string
   470  }
   471  
   472  // WithContext method
   473  func (call *DownloadRichMenuImageCall) WithContext(ctx context.Context) *DownloadRichMenuImageCall {
   474  	call.ctx = ctx
   475  	return call
   476  }
   477  
   478  // Do method
   479  func (call *DownloadRichMenuImageCall) Do() (*MessageContentResponse, error) {
   480  	endpoint := fmt.Sprintf(APIEndpointDownloadRichMenuImage, call.richMenuID)
   481  	res, err := call.c.get(call.ctx, call.c.endpointBaseData, endpoint, nil)
   482  	if err != nil {
   483  		return nil, err
   484  	}
   485  	defer closeResponse(res)
   486  	return decodeToMessageContentResponse(res)
   487  }
   488  
   489  // UploadRichMenuImage method
   490  func (client *Client) UploadRichMenuImage(richMenuID, imgPath string) *UploadRichMenuImageCall {
   491  	return &UploadRichMenuImageCall{
   492  		c:          client,
   493  		richMenuID: richMenuID,
   494  		imgPath:    imgPath,
   495  	}
   496  }
   497  
   498  // UploadRichMenuImageCall type
   499  type UploadRichMenuImageCall struct {
   500  	c   *Client
   501  	ctx context.Context
   502  
   503  	richMenuID string
   504  	imgPath    string
   505  }
   506  
   507  // WithContext method
   508  func (call *UploadRichMenuImageCall) WithContext(ctx context.Context) *UploadRichMenuImageCall {
   509  	call.ctx = ctx
   510  	return call
   511  }
   512  
   513  // Do method
   514  func (call *UploadRichMenuImageCall) Do() (*BasicResponse, error) {
   515  	body, err := os.Open(call.imgPath)
   516  	if err != nil {
   517  		return nil, err
   518  	}
   519  	defer body.Close()
   520  	fi, err := body.Stat()
   521  	if err != nil {
   522  		return nil, err
   523  	}
   524  	buf := make([]byte, 512)
   525  	n, err := body.Read(buf) // n, in case the file size < 512
   526  	if err != nil && err != io.EOF {
   527  		return nil, err
   528  	}
   529  	body.Seek(0, 0)
   530  	endpoint := fmt.Sprintf(APIEndpointUploadRichMenuImage, call.richMenuID)
   531  	req, err := http.NewRequest("POST", call.c.url(call.c.endpointBaseData, endpoint), body)
   532  	if err != nil {
   533  		return nil, err
   534  	}
   535  	req.Header.Set("Content-Type", http.DetectContentType(buf[:n]))
   536  	req.ContentLength = fi.Size()
   537  	res, err := call.c.do(call.ctx, req)
   538  	if err != nil {
   539  		return nil, err
   540  	}
   541  	defer closeResponse(res)
   542  	return decodeToBasicResponse(res)
   543  }
   544  
   545  // BulkLinkRichMenu method
   546  func (client *Client) BulkLinkRichMenu(richMenuID string, userIDs ...string) *BulkLinkRichMenuCall {
   547  	return &BulkLinkRichMenuCall{
   548  		c:          client,
   549  		userIDs:    userIDs,
   550  		richMenuID: richMenuID,
   551  	}
   552  }
   553  
   554  // BulkLinkRichMenuCall type
   555  type BulkLinkRichMenuCall struct {
   556  	c   *Client
   557  	ctx context.Context
   558  
   559  	userIDs    []string
   560  	richMenuID string
   561  }
   562  
   563  // WithContext method
   564  func (call *BulkLinkRichMenuCall) WithContext(ctx context.Context) *BulkLinkRichMenuCall {
   565  	call.ctx = ctx
   566  	return call
   567  }
   568  
   569  func (call *BulkLinkRichMenuCall) encodeJSON(w io.Writer) error {
   570  	enc := json.NewEncoder(w)
   571  	return enc.Encode(&struct {
   572  		RichMenuID string   `json:"richMenuId"`
   573  		UserIDs    []string `json:"userIds"`
   574  	}{
   575  		RichMenuID: call.richMenuID,
   576  		UserIDs:    call.userIDs,
   577  	})
   578  }
   579  
   580  // Do method
   581  func (call *BulkLinkRichMenuCall) Do() (*BasicResponse, error) {
   582  	var buf bytes.Buffer
   583  	if err := call.encodeJSON(&buf); err != nil {
   584  		return nil, err
   585  	}
   586  	res, err := call.c.post(call.ctx, APIEndpointBulkLinkRichMenu, &buf)
   587  	if err != nil {
   588  		return nil, err
   589  	}
   590  	defer closeResponse(res)
   591  	return decodeToBasicResponse(res)
   592  }
   593  
   594  // BulkUnlinkRichMenu method
   595  func (client *Client) BulkUnlinkRichMenu(userIDs ...string) *BulkUnlinkRichMenuCall {
   596  	return &BulkUnlinkRichMenuCall{
   597  		c:       client,
   598  		userIDs: userIDs,
   599  	}
   600  }
   601  
   602  // BulkUnlinkRichMenuCall type
   603  type BulkUnlinkRichMenuCall struct {
   604  	c   *Client
   605  	ctx context.Context
   606  
   607  	userIDs []string
   608  }
   609  
   610  // WithContext method
   611  func (call *BulkUnlinkRichMenuCall) WithContext(ctx context.Context) *BulkUnlinkRichMenuCall {
   612  	call.ctx = ctx
   613  	return call
   614  }
   615  
   616  func (call *BulkUnlinkRichMenuCall) encodeJSON(w io.Writer) error {
   617  	enc := json.NewEncoder(w)
   618  	return enc.Encode(&struct {
   619  		UserIDs []string `json:"userIds"`
   620  	}{
   621  		UserIDs: call.userIDs,
   622  	})
   623  }
   624  
   625  // Do method
   626  func (call *BulkUnlinkRichMenuCall) Do() (*BasicResponse, error) {
   627  	var buf bytes.Buffer
   628  	if err := call.encodeJSON(&buf); err != nil {
   629  		return nil, err
   630  	}
   631  	res, err := call.c.post(call.ctx, APIEndpointBulkUnlinkRichMenu, &buf)
   632  	if err != nil {
   633  		return nil, err
   634  	}
   635  	defer closeResponse(res)
   636  	return decodeToBasicResponse(res)
   637  }
   638  
   639  // CreateRichMenuAlias method
   640  func (client *Client) CreateRichMenuAlias(richMenuAliasID, richMenuID string) *CreateRichMenuAliasCall {
   641  	return &CreateRichMenuAliasCall{
   642  		c:               client,
   643  		richMenuAliasID: richMenuAliasID,
   644  		richMenuID:      richMenuID,
   645  	}
   646  }
   647  
   648  // CreateRichMenuAliasCall type
   649  type CreateRichMenuAliasCall struct {
   650  	c   *Client
   651  	ctx context.Context
   652  
   653  	richMenuAliasID string
   654  	richMenuID      string
   655  }
   656  
   657  // WithContext method
   658  func (call *CreateRichMenuAliasCall) WithContext(ctx context.Context) *CreateRichMenuAliasCall {
   659  	call.ctx = ctx
   660  	return call
   661  }
   662  
   663  func (call *CreateRichMenuAliasCall) encodeJSON(w io.Writer) error {
   664  	enc := json.NewEncoder(w)
   665  	return enc.Encode(&struct {
   666  		RichMenuAliasID string `json:"richMenuAliasId"`
   667  		RichMenuID      string `json:"richMenuId"`
   668  	}{
   669  		RichMenuAliasID: call.richMenuAliasID,
   670  		RichMenuID:      call.richMenuID,
   671  	})
   672  }
   673  
   674  // Do method
   675  func (call *CreateRichMenuAliasCall) Do() (*BasicResponse, error) {
   676  	var buf bytes.Buffer
   677  	if err := call.encodeJSON(&buf); err != nil {
   678  		return nil, err
   679  	}
   680  	res, err := call.c.post(call.ctx, APIEndpointCreateRichMenuAlias, &buf)
   681  	if err != nil {
   682  		return nil, err
   683  	}
   684  	defer closeResponse(res)
   685  	return decodeToBasicResponse(res)
   686  }
   687  
   688  // UpdateRichMenuAlias method
   689  func (client *Client) UpdateRichMenuAlias(richMenuAliasID, richMenuID string) *UpdateRichMenuAliasCall {
   690  	return &UpdateRichMenuAliasCall{
   691  		c:               client,
   692  		richMenuAliasID: richMenuAliasID,
   693  		richMenuID:      richMenuID,
   694  	}
   695  }
   696  
   697  // UpdateRichMenuAliasCall type
   698  type UpdateRichMenuAliasCall struct {
   699  	c   *Client
   700  	ctx context.Context
   701  
   702  	richMenuAliasID string
   703  	richMenuID      string
   704  }
   705  
   706  // WithContext method
   707  func (call *UpdateRichMenuAliasCall) WithContext(ctx context.Context) *UpdateRichMenuAliasCall {
   708  	call.ctx = ctx
   709  	return call
   710  }
   711  
   712  func (call *UpdateRichMenuAliasCall) encodeJSON(w io.Writer) error {
   713  	enc := json.NewEncoder(w)
   714  	return enc.Encode(&struct {
   715  		RichMenuID string `json:"richMenuId"`
   716  	}{
   717  		RichMenuID: call.richMenuID,
   718  	})
   719  }
   720  
   721  // Do method
   722  func (call *UpdateRichMenuAliasCall) Do() (*BasicResponse, error) {
   723  	var buf bytes.Buffer
   724  	if err := call.encodeJSON(&buf); err != nil {
   725  		return nil, err
   726  	}
   727  	endpoint := fmt.Sprintf(APIEndpointUpdateRichMenuAlias, call.richMenuAliasID)
   728  	res, err := call.c.post(call.ctx, endpoint, &buf)
   729  	if err != nil {
   730  		return nil, err
   731  	}
   732  	defer closeResponse(res)
   733  	return decodeToBasicResponse(res)
   734  }
   735  
   736  // DeleteRichMenuAlias method
   737  func (client *Client) DeleteRichMenuAlias(richMenuAliasID string) *DeleteRichMenuAliasCall {
   738  	return &DeleteRichMenuAliasCall{
   739  		c:               client,
   740  		richMenuAliasID: richMenuAliasID,
   741  	}
   742  }
   743  
   744  // DeleteRichMenuAliasCall type
   745  type DeleteRichMenuAliasCall struct {
   746  	c   *Client
   747  	ctx context.Context
   748  
   749  	richMenuAliasID string
   750  }
   751  
   752  // WithContext method
   753  func (call *DeleteRichMenuAliasCall) WithContext(ctx context.Context) *DeleteRichMenuAliasCall {
   754  	call.ctx = ctx
   755  	return call
   756  }
   757  
   758  // Do method
   759  func (call *DeleteRichMenuAliasCall) Do() (*BasicResponse, error) {
   760  	endpoint := fmt.Sprintf(APIEndpointDeleteRichMenuAlias, call.richMenuAliasID)
   761  	res, err := call.c.delete(call.ctx, endpoint)
   762  	if err != nil {
   763  		return nil, err
   764  	}
   765  	defer closeResponse(res)
   766  	return decodeToBasicResponse(res)
   767  }
   768  
   769  // GetRichMenuAlias method
   770  func (client *Client) GetRichMenuAlias(richMenuAliasID string) *GetRichMenuAliasCall {
   771  	return &GetRichMenuAliasCall{
   772  		c:               client,
   773  		richMenuAliasID: richMenuAliasID,
   774  	}
   775  }
   776  
   777  // GetRichMenuAliasCall type
   778  type GetRichMenuAliasCall struct {
   779  	c   *Client
   780  	ctx context.Context
   781  
   782  	richMenuAliasID string
   783  }
   784  
   785  // WithContext method
   786  func (call *GetRichMenuAliasCall) WithContext(ctx context.Context) *GetRichMenuAliasCall {
   787  	call.ctx = ctx
   788  	return call
   789  }
   790  
   791  // Do method
   792  func (call *GetRichMenuAliasCall) Do() (*RichMenuAliasResponse, error) {
   793  	endpoint := fmt.Sprintf(APIEndpointGetRichMenuAlias, call.richMenuAliasID)
   794  	res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil)
   795  	if err != nil {
   796  		return nil, err
   797  	}
   798  	defer closeResponse(res)
   799  	return decodeToRichMenuAliasResponse(res)
   800  }
   801  
   802  // GetRichMenuAliasList method
   803  func (client *Client) GetRichMenuAliasList() *GetRichMenuAliasListCall {
   804  	return &GetRichMenuAliasListCall{
   805  		c: client,
   806  	}
   807  }
   808  
   809  // GetRichMenuAliasListCall type
   810  type GetRichMenuAliasListCall struct {
   811  	c   *Client
   812  	ctx context.Context
   813  }
   814  
   815  // WithContext method
   816  func (call *GetRichMenuAliasListCall) WithContext(ctx context.Context) *GetRichMenuAliasListCall {
   817  	call.ctx = ctx
   818  	return call
   819  }
   820  
   821  // Do method
   822  func (call *GetRichMenuAliasListCall) Do() ([]*RichMenuAliasResponse, error) {
   823  	res, err := call.c.get(call.ctx, call.c.endpointBase, APIEndpointListRichMenuAlias, nil)
   824  	if err != nil {
   825  		return nil, err
   826  	}
   827  	defer closeResponse(res)
   828  	return decodeToRichMenuAliasListResponse(res)
   829  }
   830  
   831  // ValidateRichMenuObject method
   832  func (client *Client) ValidateRichMenuObject(richMenu RichMenu) *ValidateRichMenuObjectCall {
   833  	return &ValidateRichMenuObjectCall{
   834  		c:        client,
   835  		richMenu: richMenu,
   836  	}
   837  }
   838  
   839  // ValidateRichMenuObjectCall type
   840  type ValidateRichMenuObjectCall struct {
   841  	c   *Client
   842  	ctx context.Context
   843  
   844  	richMenu RichMenu
   845  }
   846  
   847  // WithContext method
   848  func (call *ValidateRichMenuObjectCall) WithContext(ctx context.Context) *ValidateRichMenuObjectCall {
   849  	call.ctx = ctx
   850  	return call
   851  }
   852  
   853  func (call *ValidateRichMenuObjectCall) encodeJSON(w io.Writer) error {
   854  	enc := json.NewEncoder(w)
   855  	return enc.Encode(&struct {
   856  		Size        RichMenuSize `json:"size"`
   857  		Selected    bool         `json:"selected"`
   858  		Name        string       `json:"name"`
   859  		ChatBarText string       `json:"chatBarText"`
   860  		Areas       []AreaDetail `json:"areas"`
   861  	}{
   862  		Size:        call.richMenu.Size,
   863  		Selected:    call.richMenu.Selected,
   864  		Name:        call.richMenu.Name,
   865  		ChatBarText: call.richMenu.ChatBarText,
   866  		Areas:       call.richMenu.Areas,
   867  	})
   868  }
   869  
   870  // Do method
   871  func (call *ValidateRichMenuObjectCall) Do() (*BasicResponse, error) {
   872  	var buf bytes.Buffer
   873  	if err := call.encodeJSON(&buf); err != nil {
   874  		return nil, err
   875  	}
   876  	res, err := call.c.post(call.ctx, APIEndpointValidateRichMenuObject, &buf)
   877  	if err != nil {
   878  		return nil, err
   879  	}
   880  	defer closeResponse(res)
   881  	return decodeToBasicResponse(res)
   882  }