├── .github └── workflows │ └── go.yml ├── .gitignore ├── .travis.yml ├── .vscode ├── tasks.json └── tasks.json.old ├── LICENSE ├── LineBotBabyLuis ├── Procfile ├── README.md ├── app.json ├── go.mod ├── go.sum ├── images ├── baby.PNG ├── how_learn.PNG ├── linebotH1.png ├── linebotH2.png ├── luis_learning.png ├── luis_predict.png └── qr.png ├── luis.go ├── main.go └── vendor ├── github.com ├── kkdai │ └── luis │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── client.go │ │ ├── doc.go │ │ ├── go.mod │ │ ├── go.sum │ │ ├── luis.go │ │ ├── parameters.go │ │ ├── response.go │ │ └── url.go └── line │ └── line-bot-sdk-go │ └── v7 │ ├── LICENSE.txt │ └── linebot │ ├── account_link.go │ ├── actions.go │ ├── audience.go │ ├── client.go │ ├── content_provider.go │ ├── delivery.go │ ├── demographic_filter.go │ ├── emoji.go │ ├── error.go │ ├── event.go │ ├── flex.go │ ├── flex_unmarshal.go │ ├── get_bot_info.go │ ├── get_content.go │ ├── get_count.go │ ├── get_follower_ids.go │ ├── get_ids.go │ ├── get_profile.go │ ├── get_quota.go │ ├── get_summary.go │ ├── imagemap.go │ ├── imageset.go │ ├── insight.go │ ├── leave.go │ ├── liff.go │ ├── mention.go │ ├── message.go │ ├── oauth.go │ ├── oauth2.go │ ├── progress.go │ ├── quick_reply.go │ ├── raw.go │ ├── recipient.go │ ├── response.go │ ├── richmenu.go │ ├── send_message.go │ ├── sender.go │ ├── template.go │ ├── version.go │ └── webhook.go └── modules.txt /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up Go 17 | uses: actions/setup-go@v2 18 | with: 19 | go-version: 1.15 20 | 21 | - name: Build 22 | run: go build -v ./... 23 | 24 | - name: Test 25 | run: go test -v ./... 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | LineBotBabyLuis 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - "1.13" 5 | - tip 6 | 7 | before_install: 8 | 9 | script: 10 | - go test -bench=. -benchmem ./... 11 | #- sh ./install_all_cmd.sh 12 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0.0", 3 | "command": "go", 4 | "options": { 5 | "env": { 6 | "GOPATH": "/Users/Evan/src/go" 7 | } 8 | }, 9 | "tasks": [ 10 | { 11 | "label": "install", 12 | "type": "shell", 13 | "command": "go", 14 | "args": [ 15 | "install", 16 | "-v", 17 | "./..." 18 | ], 19 | "problemMatcher": [], 20 | "group": { 21 | "_id": "build", 22 | "isDefault": false 23 | } 24 | }, 25 | { 26 | "label": "test", 27 | "type": "shell", 28 | "command": "go", 29 | "args": [ 30 | "test", 31 | "-v", 32 | "./..." 33 | ], 34 | "problemMatcher": [], 35 | "group": { 36 | "_id": "test", 37 | "isDefault": false 38 | } 39 | } 40 | ] 41 | } -------------------------------------------------------------------------------- /.vscode/tasks.json.old: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "command": "go", 4 | "isShellCommand": true, 5 | "showOutput": "silent", 6 | "options": { 7 | "env": { 8 | "GOPATH": "/Users/Evan/src/go" 9 | } 10 | }, 11 | "tasks": [ 12 | { 13 | "taskName": "install", 14 | "args": [ "-v", "./..."], 15 | "isBuildCommand": true 16 | }, 17 | { 18 | "taskName": "test", 19 | "args": [ "-v", "./..."], 20 | "isTestCommand": true 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LineBotBabyLuis: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkdai/LineBotBabyLuis/b95b75abbf361e11d3b1d58e3b3ba8fee9e090d6/LineBotBabyLuis -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: LineBotBabyLuis 2 | 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BabyLuisBot: A database-free neural-language learning Line ChatBot 2 | ============== 3 | 4 | [![Go](https://github.com/kkdai/LineBotBabyLuis/actions/workflows/go.yml/badge.svg)](https://github.com/kkdai/LineBotBabyLuis/actions/workflows/go.yml) 5 | 6 | [![GoDoc](https://godoc.org/github.com/kkdai/LineBotBabyLuis.svg?status.svg)](https://godoc.org/github.com/kkdai/LineBotBabyLuis) [![Build Status](https://travis-ci.org/kkdai/LineBotBabyLuis.svg?branch=master)](https://travis-ci.org/kkdai/LineBotBabyLuis.svg) 7 | 8 | [![goreportcard.com](https://goreportcard.com/badge/github.com/kkdai/LineBotBabyLuis)](https://goreportcard.com/report/github.com/kkdai/LineBotBabyLuis) 9 | 10 | ![](images/baby.PNG) 11 | 12 | ## Features 13 | 14 | - You don't need any database to have a NLU chatbot. 15 | - You event don't need any fee (almost) for this chatbot. (Heroku free-tier with free usage of [LUIS](https://www.luis.ai/)) 16 | 17 | How to use it 18 | --------------- 19 | 20 | ### Add friend 21 | 22 | ![](images/qr.png) 23 | 24 | ### Teach your baby 25 | 26 | - Input the word from your baby, such as "momy", "daddy" even "ne ne ..." 27 | 28 | - Input what he/she realy want, after you realize it. 29 | 30 | ![](images/how_learn.PNG) 31 | 32 | - Every time you input, your baby bot will try to learn your word. After few seconds your babt will learn it and tell you what they want. 33 | 34 | ### Auto-train and feedback 35 | 36 | Everytime your baby learn a new utterance from you, it will trigger auto-retrain. 37 | 38 | ### Limitation 39 | 40 | Because this project is just a POC (Proof of Concept), so it still don't support for multiple user online. 41 | 42 | It might have some issues if multiple user on line. 43 | 44 | Sequence Diagram 45 | --------------- 46 | 47 | ![](images/luis_predict.png) 48 | 49 | (**Sequence diagram**: LUIS could understand what user utterance means) 50 | 51 | ![](images/luis_learning.png) 52 | 53 | (**Sequence Diagram**: If user input could not identify, how LUIS LineBot learn it.) 54 | 55 | How to write your own LUIS Chatbot in Golang 56 | --------------- 57 | 58 | - Just click following button to deploy yours in Heroku. 59 | 60 | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) 61 | 62 | Note: 63 | 64 | 1. Refer [my LineBotTemplate project](https://github.com/kkdai/LineBotTemplate) for how to create your own Line Bot. 65 | 2. Refer [my Luis project](https://github.com/kkdai/luis) to know how to get `APP_ID` and `API_KEY`. 66 | 67 | - You will need a [LUIS](https://www.luis.ai/) account and create related service. 68 | - Add `APP_ID` and `API_KEY` in your heroku "Config Variables". 69 | - You need create your intent first, or you could refer my intents list 70 | - "hugs": Your baby just want hug. 71 | - "milk": Your baby want drink milk. 72 | - "pacifier": Your baby want to pacifier. 73 | - "toy": Your baby need a toy and want to play. 74 | - You will need to publish your LUIS model at least one time before Line bot run. 75 | 76 | License 77 | --------------- 78 | 79 | Licensed under the Apache License, Version 2.0 (the "License"); 80 | you may not use this file except in compliance with the License. 81 | You may obtain a copy of the License at 82 | 83 | 84 | 85 | Unless required by applicable law or agreed to in writing, software 86 | distributed under the License is distributed on an "AS IS" BASIS, 87 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 88 | See the License for the specific language governing permissions and 89 | limitations under the License. 90 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "LineBotBabyLuis", 3 | "description": "LineBot with luis feature in Go", 4 | "stack": "heroku-22", 5 | "repository": "https://github.com/kkdai/LineBotBabyLuis", 6 | "keywords": [ 7 | "Line", 8 | "go", 9 | "static" 10 | ], 11 | "buildpacks": [ 12 | { 13 | "url": "https://github.com/kr/heroku-buildpack-go.git" 14 | }, 15 | { 16 | "url": "heroku/go" 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/kkdai/LineBotBabyLuis 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/kkdai/luis v1.0.1 7 | github.com/line/line-bot-sdk-go/v7 v7.16.0 8 | ) 9 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= 3 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 4 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= 6 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 7 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 8 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 9 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 11 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 13 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 14 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 15 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 16 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 17 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 18 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 19 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 20 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 21 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 22 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 23 | github.com/kkdai/luis v1.0.1 h1:OXZHyjJTTOpDjXRKAuQBZIYkAIOzrWHL4c4AHfkZk1c= 24 | github.com/kkdai/luis v1.0.1/go.mod h1:K6ypqvZ4tseBxZRWqE/frYFcDn0IMqFIJzGL7EgqUxU= 25 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= 26 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 27 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 28 | github.com/line/line-bot-sdk-go/v7 v7.16.0 h1:vHJCYT8SN53s3Rx0pXPHPvyO+AJE5ZKLyES9m1E4mY8= 29 | github.com/line/line-bot-sdk-go/v7 v7.16.0/go.mod h1:WNSLxxBiXoGZtSfoiDKGTXu6pJJh8RGzj4AeNvSCWEs= 30 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 31 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 32 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 33 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 34 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 35 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 36 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 37 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 38 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 39 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 40 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 41 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 42 | github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 43 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 44 | github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= 45 | github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= 46 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 47 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 48 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 49 | github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= 50 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 51 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 52 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 53 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 54 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 55 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 56 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 57 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 58 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 59 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 60 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 61 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 62 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 63 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 64 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 65 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 66 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= 67 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 68 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 69 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 70 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 71 | google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 72 | gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= 73 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 74 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 75 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 76 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 77 | -------------------------------------------------------------------------------- /images/baby.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkdai/LineBotBabyLuis/b95b75abbf361e11d3b1d58e3b3ba8fee9e090d6/images/baby.PNG -------------------------------------------------------------------------------- /images/how_learn.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkdai/LineBotBabyLuis/b95b75abbf361e11d3b1d58e3b3ba8fee9e090d6/images/how_learn.PNG -------------------------------------------------------------------------------- /images/linebotH1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkdai/LineBotBabyLuis/b95b75abbf361e11d3b1d58e3b3ba8fee9e090d6/images/linebotH1.png -------------------------------------------------------------------------------- /images/linebotH2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkdai/LineBotBabyLuis/b95b75abbf361e11d3b1d58e3b3ba8fee9e090d6/images/linebotH2.png -------------------------------------------------------------------------------- /images/luis_learning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkdai/LineBotBabyLuis/b95b75abbf361e11d3b1d58e3b3ba8fee9e090d6/images/luis_learning.png -------------------------------------------------------------------------------- /images/luis_predict.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkdai/LineBotBabyLuis/b95b75abbf361e11d3b1d58e3b3ba8fee9e090d6/images/luis_predict.png -------------------------------------------------------------------------------- /images/qr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kkdai/LineBotBabyLuis/b95b75abbf361e11d3b1d58e3b3ba8fee9e090d6/images/qr.png -------------------------------------------------------------------------------- /luis.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | 7 | luis "github.com/kkdai/luis" 8 | ) 9 | 10 | //LuisAction : 11 | type LuisAction struct { 12 | LuisAPI *luis.Luis 13 | } 14 | 15 | //NewLuisAction : 16 | func NewLuisAction(appid string, appkey string) *LuisAction { 17 | l := luis.NewLuis(appkey, appid) 18 | return &LuisAction{LuisAPI: l} 19 | } 20 | 21 | //GetIntents : 22 | func (l *LuisAction) GetIntents() (*luis.IntentListResponse, *luis.ErrorResponse) { 23 | res, err := l.LuisAPI.IntelList() 24 | if err != nil { 25 | return nil, err 26 | } 27 | result := luis.NewIntentListResponse(res) 28 | return result, nil 29 | } 30 | 31 | //AddUtterance :Add new example to your intent. 32 | func (l *LuisAction) AddUtterance(intent, utterance string) { 33 | ex := luis.ExamplePayload{ExampleText: utterance, SelectedIntentName: intent} 34 | res, err := l.LuisAPI.AddLabel(ex) 35 | 36 | if err != nil { 37 | log.Println(err) 38 | return 39 | } 40 | 41 | log.Println("Done AddUtterance:", string(res)) 42 | } 43 | 44 | //Predict :Predict your example(utterance). 45 | //Note: If your model never train before, use predict will get error. 46 | func (l *LuisAction) Predict(utterance string) luis.IntentScore { 47 | //Predict it, once you have train your models. 48 | res, err := l.LuisAPI.Predict(utterance) 49 | 50 | if err != nil { 51 | log.Println("Error happen on Predict:", err.Err) 52 | return luis.IntentScore{} 53 | } 54 | log.Println("Got response:", string(res)) 55 | bestResult := luis.GetBestScoreIntent(luis.NewPredictResponse(res)) 56 | fmt.Println("Get the best predict result:", bestResult) 57 | return bestResult 58 | } 59 | 60 | //Train :Train your model, this is async call. It might take time if your data set is big. 61 | func (l *LuisAction) Train() { 62 | //Train it 63 | res, err := l.LuisAPI.Train() 64 | if err != nil { 65 | log.Println("Error happen on Trainning:", err.Err) 66 | return 67 | } 68 | log.Println("Training ret:", string(res)) 69 | 70 | ver, _ := l.LuisAPI.GetCurrentProductionVersion() 71 | 72 | //Need publish right away. 73 | res, err = l.LuisAPI.Publish(luis.PublishPayload{ 74 | VersionID: ver, 75 | IsStaging: false, 76 | Region: "westus", 77 | }) 78 | if err != nil { 79 | log.Println("Error happen on Publish:", err.Err) 80 | return 81 | } 82 | log.Println("Publish ret:", string(res)) 83 | } 84 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Licensed under the Apache License, Version 2.0 (the "License"); 2 | // you may not use this file except in compliance with the License. 3 | // You may obtain a copy of the License at 4 | // 5 | // http://www.apache.org/licenses/LICENSE-2.0 6 | // 7 | // Unless required by applicable law or agreed to in writing, software 8 | // distributed under the License is distributed on an "AS IS" BASIS, 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | // See the License for the specific language governing permissions and 11 | // limitations under the License. 12 | 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "log" 18 | "net/http" 19 | "os" 20 | "strings" 21 | 22 | luis "github.com/kkdai/luis" 23 | "github.com/line/line-bot-sdk-go/v7/linebot" 24 | ) 25 | 26 | var bot *linebot.Client 27 | var luisAction *LuisAction 28 | var allIntents *luis.IntentListResponse 29 | var currentUtterance string 30 | 31 | func main() { 32 | var err error 33 | appID := os.Getenv("APP_ID") 34 | apiKey := os.Getenv("APP_KEY") 35 | log.Println("Luis:", appID, apiKey) 36 | luisAction = NewLuisAction(appID, apiKey) 37 | 38 | bot, err = linebot.New(os.Getenv("ChannelSecret"), os.Getenv("ChannelAccessToken")) 39 | log.Println("Bot:", bot, " err:", err) 40 | http.HandleFunc("/callback", callbackHandler) 41 | port := os.Getenv("PORT") 42 | addr := fmt.Sprintf(":%s", port) 43 | http.ListenAndServe(addr, nil) 44 | } 45 | 46 | func callbackHandler(w http.ResponseWriter, r *http.Request) { 47 | events, err := bot.ParseRequest(r) 48 | 49 | if err != nil { 50 | if err == linebot.ErrInvalidSignature { 51 | w.WriteHeader(400) 52 | } else { 53 | w.WriteHeader(500) 54 | } 55 | return 56 | } 57 | 58 | for _, event := range events { 59 | switch event.Type { 60 | case linebot.EventTypeMessage: 61 | log.Println("event.Type == EventTypeMessage") 62 | switch message := event.Message.(type) { 63 | case *linebot.TextMessage: 64 | res, err := luisAction.GetIntents() 65 | if err != nil { 66 | log.Println(err) 67 | return 68 | } 69 | var intentList []string 70 | log.Println("All intent:", *res) 71 | for _, v := range *res { 72 | if strings.EqualFold(message.Text, v.Name) { 73 | //if input text equal to intents, just leave. (ignore dual event on post action) 74 | return 75 | } 76 | 77 | if v.Name != "None" { 78 | intentList = append(intentList, v.Name) 79 | } 80 | } 81 | 82 | ret := luisAction.Predict(message.Text) 83 | if ret.Intent == "None" || ret.Intent == "" || ret.Score < 0.5 { 84 | //List all intents 85 | ListAllIntents(bot, event.ReplyToken, intentList, message.Text) 86 | 87 | } else { 88 | if _, err := bot.ReplyMessage(event.ReplyToken, linebot.NewTextMessage(fmt.Sprintf("Daddy/Mommy, I just want to %s (%d %%)", ret.Intent, int(ret.Score*100)))).Do(); err != nil { 89 | log.Print(err) 90 | } 91 | } 92 | } 93 | case linebot.EventTypePostback: 94 | log.Println("event.Type == linebot.EventTypePostback") 95 | //Add new utterance into original intent 96 | luisAction.AddUtterance(event.Postback.Data, currentUtterance) 97 | 98 | retStr := fmt.Sprintf("Daddy/Mommy, I just learn new utterance %s for intent: %s.", currentUtterance, event.Postback.Data) 99 | if _, err = bot.ReplyMessage(event.ReplyToken, linebot.NewTextMessage(retStr)).Do(); err != nil { 100 | log.Print(err) 101 | } 102 | 103 | //Train it right away 104 | luisAction.Train() 105 | return 106 | } 107 | } 108 | } 109 | 110 | //ListAllIntents : 111 | func ListAllIntents(bot *linebot.Client, replyToken string, intents []string, utterance string) { 112 | askStmt := fmt.Sprintf("Your utterance %s is not exist, please select correct intent.", utterance) 113 | log.Println("askStmt:", askStmt) 114 | 115 | var sliceTemplateAction []linebot.TemplateAction 116 | for _, v := range intents { 117 | sliceTemplateAction = append(sliceTemplateAction, linebot.NewPostbackAction(v, v, v, "", linebot.InputOptionCloseRichMenu, "")) 118 | } 119 | 120 | template := linebot.NewButtonsTemplate("", "Select your intent for your baby", utterance, sliceTemplateAction...) 121 | 122 | if _, err := bot.ReplyMessage( 123 | replyToken, 124 | linebot.NewTemplateMessage("Select your intent for your baby", template)).Do(); err != nil { 125 | log.Print(err) 126 | } 127 | currentUtterance = utterance 128 | } 129 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/.gitignore: -------------------------------------------------------------------------------- 1 | main 2 | example 3 | *.wav 4 | .vscode 5 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - "1.13" 5 | - tip 6 | 7 | before_install: 8 | 9 | script: 10 | - go test -bench=. -benchmem ./... -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Evan Lin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/README.md: -------------------------------------------------------------------------------- 1 | LUIS.ai for Golang 2 | ====================== 3 | [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/kkdai/luis/master/LICENSE) [![GoDoc](https://godoc.org/github.com/kkdai/luis?status.svg)](https://godoc.org/github.com/kkdai/luis) [![Build Status](https://travis-ci.org/kkdai/luis.svg)](https://travis-ci.org/kkdai/luis) 4 | 5 | 6 | 7 | ## Language Understanding Intelligent Service (LUIS) 8 | 9 | LUIS lets your app understand language 10 | 11 | - LUIS is in beta and free to use 12 | - Supported browsers: Internet Explorer 10/11, Chrome 13 | 14 | In LUIS you can: 15 | 16 | - Create language understanding models. 17 | - Use pre-built, world-class models from Bing and Cortana. 18 | - Deploy your models to an HTTP endpoint. 19 | - Activate models on any device. 20 | 21 | Here is some suggestion and limitation you might want to check before add all you intent. [Chinese](https://ericyeh92094.gitbooks.io/a-simple-wechat-chatbot-generator/content/generator/%E8%87%AA%E7%84%B6%E8%AA%9E%E8%A8%80%E8%99%95%E7%90%86.html) 22 | 23 | ## How to get APP_ID and APP_KEY 24 | 25 | ### APP_KEY 26 | 27 | Login and go to LUIS key page [https://www.luis.ai/home/keys](https://www.luis.ai/home/keys) 28 | 29 | You can see the `API_KEY` in "My Keys". 30 | 31 | ![](images/luis_api.png) 32 | 33 | ### APP_ID 34 | 35 | Create a new App (if you don't have one) and in the APP dashboard, you can get `APP_ID` from web URL. It might be `12341be8-8cfb-471c-b05a-636d58cd5678` 36 | 37 | ![](images/APP_ID.png) 38 | 39 | ### Version ID (Important) 40 | 41 | Before use this SDK, you must run follow step in luis.ai dashboard. 42 | 43 | - Create new app 44 | - Add few intent 45 | - Add `Endpoint Key` (You could use your API key) 46 | - Publish your model. 47 | 48 | Installation 49 | --------------- 50 | 51 | ``` 52 | go get github.com/kkdai/luis 53 | ``` 54 | 55 | How to use it 56 | --------------- 57 | 58 | ```go 59 | var API_KEY string 60 | var APPID string 61 | 62 | func main() { 63 | var API_KEY string 64 | var APPID string 65 | 66 | APPID = os.Getenv("APP_ID") 67 | API_KEY = os.Getenv("SUB_KEY") 68 | 69 | if API_KEY == "" { 70 | fmt.Println("Please export your key to environment first, `export SUB_KEY=12234 && export APP_ID=5678`") 71 | } 72 | if API_KEY == "" { 73 | return 74 | } 75 | 76 | e := NewLuis(API_KEY, APPID) 77 | 78 | res, err := e.IntelList() 79 | 80 | if err != nil { 81 | log.Error("Error happen on :", err.Err) 82 | } 83 | fmt.Println("Got response:", string(res)) 84 | result := NewIntentListResponse(res) 85 | fmt.Println("Luis Intent Ret", result) 86 | 87 | //Add utterances 88 | ex := ExampleJson{ExampleText: "test", SelectedIntentName: "test2"} 89 | res, err = e.AddLabel(ex) 90 | 91 | //Train it 92 | res, err = e.Train() 93 | if err != nil { 94 | log.Error("Error happen on :", err.Err) 95 | } 96 | 97 | //Predict it, once you have train your models. 98 | res, err = e.Predict("test string") 99 | 100 | if err != nil { 101 | log.Error("Error happen on :", err.Err) 102 | } 103 | fmt.Println("Got response:", string(res)) 104 | fmt.Println("Get the best predict result:", GetBestScoreIntent(NewPredictResponse(res))) 105 | } 106 | ``` 107 | 108 | Implemented APIs 109 | --------------- 110 | 111 | - actionChannels 112 | - intents 113 | - predict 114 | - train 115 | - example 116 | - Versions 117 | - Publish 118 | 119 | 120 | Unimplement APIs (Yet) 121 | --------------- 122 | 123 | Need your help to send your PR. 124 | 125 | Contribute 126 | --------------- 127 | 128 | Please open up an issue on GitHub before you put a lot efforts on pull request. 129 | The code submitting to PR must be filtered with `gofmt` 130 | 131 | License 132 | --------------- 133 | 134 | This package is licensed under MIT license. See LICENSE for details. 135 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/client.go: -------------------------------------------------------------------------------- 1 | package luis 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "fmt" 7 | "io/ioutil" 8 | "log" 9 | "net/http" 10 | ) 11 | 12 | const ( 13 | StreamContent string = "application/octet-stream" 14 | JsonContent string = "application/json" 15 | ) 16 | 17 | //Client: 18 | type Client struct { 19 | key string 20 | } 21 | 22 | //NewClient: New oxford client based on key 23 | func NewClient(key string) *Client { 24 | c := new(Client) 25 | c.key = key 26 | 27 | return c 28 | } 29 | 30 | //Connect :with API url and data, return response byte or error if http.Status is not OK 31 | func (c *Client) Connect(mode string, inUrl string, data *bytes.Buffer, useJson bool) ([]byte, *ErrorResponse) { 32 | client := &http.Client{} 33 | fmt.Println("connected: ", mode, inUrl, data) 34 | 35 | r := &http.Request{} 36 | if data == nil { 37 | r, _ = http.NewRequest(mode, inUrl, nil) 38 | 39 | } else { 40 | r, _ = http.NewRequest(mode, inUrl, data) 41 | } 42 | 43 | if useJson { 44 | r.Header.Add("Content-Type", JsonContent) 45 | } else { 46 | r.Header.Add("Content-Type", StreamContent) 47 | } 48 | 49 | r.Header.Add("Ocp-Apim-Subscription-Key", c.key) 50 | ret := new(ErrorResponse) 51 | resp, err := client.Do(r) 52 | 53 | if err != nil { 54 | log.Println("er:", err) 55 | ret.Err = err 56 | return nil, ret 57 | } 58 | 59 | body, err := ioutil.ReadAll(resp.Body) 60 | if err != nil { 61 | log.Println("er:", err) 62 | ret.Err = err 63 | return nil, ret 64 | } 65 | 66 | if resp.StatusCode > http.StatusAccepted { 67 | ret.ErrorCode = resp.StatusCode 68 | ret.Err = errors.New("Error on:" + string(body)) 69 | log.Println("Error happen! body:", string(body)) 70 | return body, ret 71 | } 72 | 73 | return body, nil 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package luis is a tools to access Microsoft Translator marketplace API. 3 | For more detail, please refer to https://www.microsoft.com/translator/api.aspx 4 | 5 | */ 6 | package luis 7 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/kkdai/luis 2 | 3 | go 1.13 4 | 5 | require github.com/prometheus/common v0.9.1 6 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 2 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= 3 | github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 4 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 5 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4 h1:Hs82Z41s6SdL1CELW+XaDYmOH4hkBN4/N9og/AsOv7E= 6 | github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 7 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 8 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 9 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 11 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 13 | github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 14 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 15 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 16 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 17 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 18 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 19 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 20 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 21 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 22 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 23 | github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= 24 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 25 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 26 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 27 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 28 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 29 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 30 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 31 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 32 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 33 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 34 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 35 | github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= 36 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 37 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 38 | github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 39 | github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 40 | github.com/prometheus/common v0.9.1 h1:KOMtN28tlbam3/7ZKEYKHhKoJZYYj3gMH4uc62x7X7U= 41 | github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= 42 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 43 | github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 44 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 45 | github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= 46 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 47 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 48 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 49 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 50 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= 51 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 52 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 53 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 54 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 55 | golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 56 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 57 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 58 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 59 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 60 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 61 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= 62 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 63 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 64 | gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= 65 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 66 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 67 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 68 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 69 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/luis.go: -------------------------------------------------------------------------------- 1 | package luis 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "fmt" 7 | "log" 8 | "net/url" 9 | ) 10 | 11 | //Luis : 12 | type Luis struct { 13 | appid string 14 | versionid string 15 | client *Client 16 | } 17 | 18 | //NewLuis : 19 | func NewLuis(key string, appid string) *Luis { 20 | if len(key) == 0 { 21 | return nil 22 | } 23 | 24 | e := new(Luis) 25 | e.appid = appid 26 | e.client = NewClient(key) 27 | res, err := e.GetAppInfo() 28 | if err != nil { 29 | fmt.Println(err, "Cannot get app info") 30 | return nil 31 | } 32 | app := NewAppInfo(res) 33 | fmt.Println(app) 34 | 35 | e.versionid = app.Endpoints.PRODUCTION.VersionID 36 | fmt.Println(e.versionid) 37 | return e 38 | } 39 | 40 | //GetAppInfo :Get App detail info and refresh app version id. 41 | func (l *Luis) GetAppInfo() ([]byte, *ErrorResponse) { 42 | url := getAppInfo(l.appid) 43 | fmt.Println("app detail URL=", url) 44 | 45 | return l.client.Connect("GET", url, nil, true) 46 | } 47 | 48 | //IntelList :Get All Intent List of this app 49 | //Retreives information about the intent models. 50 | func (l *Luis) IntelList() ([]byte, *ErrorResponse) { 51 | url := getIntentListURL(l.appid, l.versionid) 52 | fmt.Println("intent list URL=", url) 53 | return l.client.Connect("GET", url, nil, true) 54 | } 55 | 56 | //ActionChannels :get Available Action Channels 57 | //gets a list of all available action channels for the application 58 | func (l *Luis) ActionChannels() ([]byte, *ErrorResponse) { 59 | url := getActionChannels(l.appid, l.versionid) 60 | return l.client.Connect("GET", url, nil, true) 61 | } 62 | 63 | //Predict :get Train Model Predictions 64 | //gets the trained model predictions for the input examples 65 | func (l *Luis) Predict(utterance string) ([]byte, *ErrorResponse) { 66 | outUrl := getPredictURL(l.appid, l.versionid) 67 | utterance = url.QueryEscape(utterance) 68 | outUrl = outUrl + "?subscription-key=" + l.client.key + "&q=" + utterance 69 | return l.client.Connect("GET", outUrl, nil, true) 70 | } 71 | 72 | //Train :Training Status 73 | //gets the training status of all models of the specified application 74 | func (l *Luis) Train() ([]byte, *ErrorResponse) { 75 | url := getTrainURL(l.appid, l.versionid) 76 | return l.client.Connect("POST", url, nil, true) 77 | } 78 | 79 | //AddLabel :Add Label 80 | // Adds a labeled example to the specified application 81 | func (l *Luis) AddLabel(example ExamplePayload) ([]byte, *ErrorResponse) { 82 | url := getAddExampleURL(l.appid, l.versionid) 83 | bytExample, err := json.Marshal(example) 84 | if err != nil { 85 | log.Println("err:", err) 86 | return nil, nil 87 | } 88 | return l.client.Connect("POST", url, bytes.NewBuffer(bytExample), true) 89 | } 90 | 91 | //Publish :Publishes a specific version of the application 92 | func (l *Luis) Publish(payload PublishPayload) ([]byte, *ErrorResponse) { 93 | url := getPublishURL(l.appid, l.versionid) 94 | bytPayload, err := json.Marshal(payload) 95 | if err != nil { 96 | log.Println("err:", err) 97 | return nil, nil 98 | } 99 | return l.client.Connect("POST", url, bytes.NewBuffer(bytPayload), true) 100 | } 101 | 102 | //Version :Get application version 103 | func (l *Luis) Version(versionID string) ([]byte, *ErrorResponse) { 104 | outUrl := getVersionURL(l.appid, l.versionid) 105 | versionID = url.QueryEscape(versionID) 106 | outUrl = outUrl + "/" + versionID + "/" 107 | return l.client.Connect("GET", outUrl, nil, true) 108 | } 109 | 110 | //Version :Get application version 111 | func (l *Luis) Versions() ([]byte, *ErrorResponse) { 112 | outUrl := getVersionURL(l.appid, l.versionid) 113 | outUrl = outUrl + "/" 114 | return l.client.Connect("GET", outUrl, nil, true) 115 | } 116 | 117 | func (l *Luis) GetCurrentProductionVersion() (string, *ErrorResponse) { 118 | if l.versionid != "" { 119 | return l.versionid, nil 120 | } 121 | return "", &ErrorResponse{ 122 | ErrorCode: 500, 123 | Err: fmt.Errorf("No production model.\n"), 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/parameters.go: -------------------------------------------------------------------------------- 1 | package luis 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io/ioutil" 7 | "log" 8 | ) 9 | 10 | func getBooleanString(b bool) string { 11 | if b { 12 | return "true" 13 | } else { 14 | return "false" 15 | } 16 | } 17 | 18 | func getFileByteBuffer(path string) (*bytes.Buffer, error) { 19 | fileData, err := ioutil.ReadFile(path) 20 | 21 | if err != nil { 22 | log.Println("File open err:", err) 23 | return nil, err 24 | } 25 | return bytes.NewBuffer(fileData), nil 26 | } 27 | 28 | func getUrlByteBuffer(url string) *bytes.Buffer { 29 | byteData := []byte(fmt.Sprintf(`{"url":"%s"}`, url)) 30 | return bytes.NewBuffer(byteData) 31 | 32 | } 33 | 34 | func getUserDataByteBuffer(userData string) *bytes.Buffer { 35 | byteData := []byte(fmt.Sprintf(`{"userData":"%s"}`, userData)) 36 | return bytes.NewBuffer(byteData) 37 | 38 | } 39 | 40 | func getStringDataByteBuffer(userData string) *bytes.Buffer { 41 | byteData := []byte(fmt.Sprintf(`["%s"]`, userData)) 42 | return bytes.NewBuffer(byteData) 43 | 44 | } 45 | 46 | //ExamplePayload : 47 | type ExamplePayload struct { 48 | ExampleText string `json:"text"` 49 | SelectedIntentName string `json:"intentName"` 50 | EntityLabels []struct { 51 | EntityType string `json:"entityName"` 52 | StartToken int `json:"startCharIndex"` 53 | EndToken int `json:"endCharIndex"` 54 | } `json:"entityLabels,omitempty"` 55 | } 56 | 57 | type PublishPayload struct { 58 | VersionID string `json:"versionId"` 59 | IsStaging bool `json:"isStaging"` 60 | Region string `json:"region"` 61 | } 62 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/response.go: -------------------------------------------------------------------------------- 1 | package luis 2 | 3 | import ( 4 | "encoding/json" 5 | "log" 6 | "time" 7 | ) 8 | 9 | //AppInfo : Display app detail info 10 | type AppInfo struct { 11 | ID string `json:"id"` 12 | Name string `json:"name"` 13 | Description interface{} `json:"description"` 14 | Culture string `json:"culture"` 15 | UsageScenario string `json:"usageScenario"` 16 | Domain string `json:"domain"` 17 | VersionsCount int `json:"versionsCount"` 18 | CreatedDateTime time.Time `json:"createdDateTime"` 19 | Endpoints struct { 20 | PRODUCTION struct { 21 | VersionID string `json:"versionId"` 22 | IsStaging bool `json:"isStaging"` 23 | EndpointURL string `json:"endpointUrl"` 24 | AssignedEndpointKey string `json:"assignedEndpointKey"` 25 | PublishedDateTime time.Time `json:"publishedDateTime"` 26 | } `json:"PRODUCTION"` 27 | } `json:"endpoints"` 28 | EndpointHitsCount int `json:"endpointHitsCount"` 29 | } 30 | 31 | //IntentListResponse : 32 | type IntentListResponse []struct { 33 | ID string `json:"id"` 34 | Name string `json:"name"` 35 | Type string `json:"type"` 36 | } 37 | 38 | //NewAppInfo : 39 | func NewAppInfo(raw []byte) *AppInfo { 40 | ret := &AppInfo{} 41 | err := json.Unmarshal(raw, &ret) 42 | if err != nil { 43 | log.Println("json unmarshal err:", err) 44 | return ret 45 | } 46 | return ret 47 | } 48 | 49 | //NewIntentListResponse : 50 | func NewIntentListResponse(raw []byte) *IntentListResponse { 51 | ret := &IntentListResponse{} 52 | err := json.Unmarshal(raw, &ret) 53 | if err != nil { 54 | log.Println("json unmarshal err:", err) 55 | return ret 56 | } 57 | return ret 58 | } 59 | 60 | //ErrorResponse : 61 | //Storage all HTTP response include http.response code and error code 62 | type ErrorResponse struct { 63 | ErrorCode int 64 | Err error 65 | } 66 | 67 | //ActionChannelsResponse : 68 | type ActionChannelsResponse []struct { 69 | Name string `json:"Name"` 70 | Version int `json:"Version"` 71 | SupportURI string `json:"SupportUri"` 72 | Actions []struct { 73 | Name string `json:"Name"` 74 | Parameters []struct { 75 | Name string `json:"Name"` 76 | DataType string `json:"DataType"` 77 | PlaceHolderText string `json:"PlaceHolderText"` 78 | Required bool `json:"Required"` 79 | } `json:"Parameters"` 80 | SupportedAuthenticationTypes []int `json:"SupportedAuthenticationTypes"` 81 | } `json:"Actions"` 82 | } 83 | 84 | type IntentsResultType struct { 85 | Name string `json:"Name"` 86 | Label interface{} `json:"label"` 87 | Score float64 `json:"score"` 88 | } 89 | 90 | //PredictResponse : 91 | type PredictResponse struct { 92 | Query string `json:"query"` 93 | TopScoringIntent IntentScore `json:"topScoringIntent"` 94 | TotalIntents []IntentScore `json:"intents"` 95 | Entities interface{} `json:"entities"` 96 | } 97 | 98 | type IntentScore struct { 99 | Intent string `json:"intent"` 100 | Score float32 `json:"score"` 101 | } 102 | 103 | //NewPredictResponse : 104 | func NewPredictResponse(raw []byte) *PredictResponse { 105 | ret := &PredictResponse{} 106 | err := json.Unmarshal(raw, &ret) 107 | if err != nil { 108 | log.Println("json unmarshal err:", err) 109 | return ret 110 | } 111 | return ret 112 | } 113 | 114 | //GetBestScoreIntent :Get the best score intent prediction 115 | func GetBestScoreIntent(preResult *PredictResponse) IntentScore { 116 | return preResult.TopScoringIntent 117 | } 118 | -------------------------------------------------------------------------------- /vendor/github.com/kkdai/luis/url.go: -------------------------------------------------------------------------------- 1 | package luis 2 | 3 | const ( 4 | //LuisURL :Basic URL (V1.0) 5 | LuisURL string = "https://westus.api.cognitive.microsoft.com/luis/api/v2.0/apps/" 6 | // {ap/pId}/versions/{versionId}/example 7 | 8 | //LuisAPIIntents :API Intent List 9 | LuisAPIIntents string = "intents" 10 | //LuisAPIActionChannels :API Action Channels 11 | LuisAPIActionChannels string = "actionChannels" 12 | //LuisAPIPredict :API Predict 13 | LuisAPIPredict string = "predict" 14 | //LuisAPITrain :API Train 15 | LuisAPITrain string = "train" 16 | //LuisAPIAddExample :API Add Label 17 | LuisAPIAddExample string = "example" 18 | //LuisAPIPublish :API Publish your application 19 | LuisAPIPublish string = "publish" 20 | //LuisAPIVersion :API Get application version 21 | LuisAPIVersion string = "version" 22 | ) 23 | 24 | func getAppInfo(appid string) string { 25 | return LuisURL + appid 26 | } 27 | func getIntentListURL(apid string, versionid string) string { 28 | return LuisURL + apid + "/versions/" + versionid + "/" + LuisAPIIntents 29 | } 30 | 31 | func getActionChannels(apid string, versionid string) string { 32 | return LuisURL + apid + "/versions/" + versionid + "/" + LuisAPIActionChannels 33 | } 34 | 35 | func getPredictURL(apid string, versionid string) string { 36 | return "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" + apid 37 | } 38 | 39 | func getTrainURL(apid string, versionid string) string { 40 | return LuisURL + apid + "/versions/" + versionid + "/" + LuisAPITrain 41 | } 42 | 43 | func getAddExampleURL(apid string, versionid string) string { 44 | return LuisURL + apid + "/versions/" + versionid + "/" + LuisAPIAddExample 45 | } 46 | 47 | func getPublishURL(apid string, versionid string) string { 48 | return LuisURL + apid + "/" + LuisAPIPublish 49 | } 50 | 51 | func getVersionURL(apid string, versionid string) string { 52 | return LuisURL + apid + "/versions/" 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright (C) 2016 LINE Corp. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/account_link.go: -------------------------------------------------------------------------------- 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 | "context" 19 | "fmt" 20 | ) 21 | 22 | // IssueLinkToken method 23 | // https://developers.line.me/en/reference/messaging-api/#issue-link-token 24 | func (client *Client) IssueLinkToken(userID string) *IssueLinkTokenCall { 25 | return &IssueLinkTokenCall{ 26 | c: client, 27 | userID: userID, 28 | } 29 | } 30 | 31 | // IssueLinkTokenCall type 32 | type IssueLinkTokenCall struct { 33 | c *Client 34 | ctx context.Context 35 | 36 | userID string 37 | } 38 | 39 | // WithContext method 40 | func (call *IssueLinkTokenCall) WithContext(ctx context.Context) *IssueLinkTokenCall { 41 | call.ctx = ctx 42 | return call 43 | } 44 | 45 | // Do method 46 | func (call *IssueLinkTokenCall) Do() (*LinkTokenResponse, error) { 47 | endpoint := fmt.Sprintf(APIEndpointLinkToken, call.userID) 48 | res, err := call.c.post(call.ctx, endpoint, nil) 49 | if err != nil { 50 | return nil, err 51 | } 52 | defer closeResponse(res) 53 | return decodeToLinkTokenResponse(res) 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/actions.go: -------------------------------------------------------------------------------- 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 "encoding/json" 18 | 19 | // ActionType type 20 | type ActionType string 21 | 22 | // ActionType constants 23 | const ( 24 | ActionTypeURI ActionType = "uri" 25 | ActionTypeMessage ActionType = "message" 26 | ActionTypePostback ActionType = "postback" 27 | ActionTypeDatetimePicker ActionType = "datetimepicker" 28 | ActionTypeCamera ActionType = "camera" 29 | ActionTypeCameraRoll ActionType = "cameraRoll" 30 | ActionTypeLocation ActionType = "location" 31 | ) 32 | 33 | // InputOption type 34 | type InputOption string 35 | 36 | // InputOption constants 37 | const ( 38 | InputOptionCloseRichMenu InputOption = "closeRichMenu" 39 | InputOptionOpenRichMenu InputOption = "openRichMenu" 40 | InputOptionOpenKeyboard InputOption = "openKeyboard" 41 | InputOptionOpenVoice InputOption = "openVoice" 42 | ) 43 | 44 | // Action interface 45 | type Action interface { 46 | json.Marshaler 47 | } 48 | 49 | // TemplateAction interface 50 | type TemplateAction interface { 51 | Action 52 | TemplateAction() 53 | } 54 | 55 | // QuickReplyAction type 56 | type QuickReplyAction interface { 57 | Action 58 | QuickReplyAction() 59 | } 60 | 61 | // URIAction type 62 | type URIAction struct { 63 | Label string 64 | URI string 65 | AltURI *URIActionAltURI 66 | } 67 | 68 | // URIActionAltURI type 69 | type URIActionAltURI struct { 70 | Desktop string `json:"desktop"` 71 | } 72 | 73 | // MarshalJSON method of URIAction 74 | func (a *URIAction) MarshalJSON() ([]byte, error) { 75 | return json.Marshal(&struct { 76 | Type ActionType `json:"type"` 77 | Label string `json:"label,omitempty"` 78 | URI string `json:"uri"` 79 | AltURI *URIActionAltURI `json:"altUri,omitempty"` 80 | }{ 81 | Type: ActionTypeURI, 82 | Label: a.Label, 83 | URI: a.URI, 84 | AltURI: a.AltURI, 85 | }) 86 | } 87 | 88 | // MessageAction type 89 | type MessageAction struct { 90 | Label string 91 | Text string 92 | } 93 | 94 | // MarshalJSON method of MessageAction 95 | func (a *MessageAction) MarshalJSON() ([]byte, error) { 96 | return json.Marshal(&struct { 97 | Type ActionType `json:"type"` 98 | Label string `json:"label,omitempty"` 99 | Text string `json:"text"` 100 | }{ 101 | Type: ActionTypeMessage, 102 | Label: a.Label, 103 | Text: a.Text, 104 | }) 105 | } 106 | 107 | // PostbackAction type 108 | type PostbackAction struct { 109 | Label string 110 | Data string 111 | Text string 112 | DisplayText string 113 | InputOption InputOption 114 | FillInText string 115 | } 116 | 117 | // MarshalJSON method of PostbackAction 118 | func (a *PostbackAction) MarshalJSON() ([]byte, error) { 119 | return json.Marshal(&struct { 120 | Type ActionType `json:"type"` 121 | Label string `json:"label,omitempty"` 122 | Data string `json:"data"` 123 | Text string `json:"text,omitempty"` 124 | DisplayText string `json:"displayText,omitempty"` 125 | InputOption InputOption `json:"inputOption,omitempty"` 126 | FillInText string `json:"fillInText,omitempty"` 127 | }{ 128 | Type: ActionTypePostback, 129 | Label: a.Label, 130 | Data: a.Data, 131 | Text: a.Text, 132 | DisplayText: a.DisplayText, 133 | InputOption: a.InputOption, 134 | FillInText: a.FillInText, 135 | }) 136 | } 137 | 138 | // DatetimePickerAction type 139 | type DatetimePickerAction struct { 140 | Label string 141 | Data string 142 | Mode string 143 | Initial string 144 | Max string 145 | Min string 146 | } 147 | 148 | // MarshalJSON method of DatetimePickerAction 149 | func (a *DatetimePickerAction) MarshalJSON() ([]byte, error) { 150 | return json.Marshal(&struct { 151 | Type ActionType `json:"type"` 152 | Label string `json:"label,omitempty"` 153 | Data string `json:"data"` 154 | Mode string `json:"mode"` 155 | Initial string `json:"initial,omitempty"` 156 | Max string `json:"max,omitempty"` 157 | Min string `json:"min,omitempty"` 158 | }{ 159 | Type: ActionTypeDatetimePicker, 160 | Label: a.Label, 161 | Data: a.Data, 162 | Mode: a.Mode, 163 | Initial: a.Initial, 164 | Max: a.Max, 165 | Min: a.Min, 166 | }) 167 | } 168 | 169 | // CameraAction type 170 | type CameraAction struct { 171 | Label string 172 | } 173 | 174 | // MarshalJSON method of CameraAction 175 | func (a *CameraAction) MarshalJSON() ([]byte, error) { 176 | return json.Marshal(&struct { 177 | Type ActionType `json:"type"` 178 | Label string `json:"label"` 179 | }{ 180 | Type: ActionTypeCamera, 181 | Label: a.Label, 182 | }) 183 | } 184 | 185 | // CameraRollAction type 186 | type CameraRollAction struct { 187 | Label string 188 | } 189 | 190 | // MarshalJSON method of CameraRollAction 191 | func (a *CameraRollAction) MarshalJSON() ([]byte, error) { 192 | return json.Marshal(&struct { 193 | Type ActionType `json:"type"` 194 | Label string `json:"label"` 195 | }{ 196 | Type: ActionTypeCameraRoll, 197 | Label: a.Label, 198 | }) 199 | } 200 | 201 | // LocationAction type 202 | type LocationAction struct { 203 | Label string 204 | } 205 | 206 | // MarshalJSON method of LocationAction 207 | func (a *LocationAction) MarshalJSON() ([]byte, error) { 208 | return json.Marshal(&struct { 209 | Type ActionType `json:"type"` 210 | Label string `json:"label"` 211 | }{ 212 | Type: ActionTypeLocation, 213 | Label: a.Label, 214 | }) 215 | } 216 | 217 | // TemplateAction implements TemplateAction interface 218 | func (*URIAction) TemplateAction() {} 219 | 220 | // TemplateAction implements TemplateAction interface 221 | func (*MessageAction) TemplateAction() {} 222 | 223 | // TemplateAction implements TemplateAction interface 224 | func (*PostbackAction) TemplateAction() {} 225 | 226 | // TemplateAction implements TemplateAction interface 227 | func (*DatetimePickerAction) TemplateAction() {} 228 | 229 | // QuickReplyAction implements QuickReplyAction interface 230 | func (*MessageAction) QuickReplyAction() {} 231 | 232 | // QuickReplyAction implements QuickReplyAction interface 233 | func (*PostbackAction) QuickReplyAction() {} 234 | 235 | // QuickReplyAction implements QuickReplyAction interface 236 | func (*DatetimePickerAction) QuickReplyAction() {} 237 | 238 | // QuickReplyAction implements QuickReplyAction interface 239 | func (*CameraAction) QuickReplyAction() {} 240 | 241 | // QuickReplyAction implements QuickReplyAction interface 242 | func (*CameraRollAction) QuickReplyAction() {} 243 | 244 | // QuickReplyAction implements QuickReplyAction interface 245 | func (*LocationAction) QuickReplyAction() {} 246 | 247 | // QuickReplyAction implements URI's QuickReplyAction interface 248 | func (*URIAction) QuickReplyAction() {} 249 | 250 | // NewURIAction function 251 | func NewURIAction(label, uri string) *URIAction { 252 | return &URIAction{ 253 | Label: label, 254 | URI: uri, 255 | } 256 | } 257 | 258 | // NewMessageAction function 259 | func NewMessageAction(label, text string) *MessageAction { 260 | return &MessageAction{ 261 | Label: label, 262 | Text: text, 263 | } 264 | } 265 | 266 | // NewPostbackAction function 267 | func NewPostbackAction(label, data, text, displayText string, inputOption InputOption, fillInText string) *PostbackAction { 268 | return &PostbackAction{ 269 | Label: label, 270 | Data: data, 271 | Text: text, 272 | DisplayText: displayText, 273 | InputOption: inputOption, 274 | FillInText: fillInText, 275 | } 276 | } 277 | 278 | // NewDatetimePickerAction function 279 | func NewDatetimePickerAction(label, data, mode, initial, max, min string) *DatetimePickerAction { 280 | return &DatetimePickerAction{ 281 | Label: label, 282 | Data: data, 283 | Mode: mode, 284 | Initial: initial, 285 | Max: max, 286 | Min: min, 287 | } 288 | } 289 | 290 | // NewCameraAction function 291 | func NewCameraAction(label string) *CameraAction { 292 | return &CameraAction{ 293 | Label: label, 294 | } 295 | } 296 | 297 | // NewCameraRollAction function 298 | func NewCameraRollAction(label string) *CameraRollAction { 299 | return &CameraRollAction{ 300 | Label: label, 301 | } 302 | } 303 | 304 | // NewLocationAction function 305 | func NewLocationAction(label string) *LocationAction { 306 | return &LocationAction{ 307 | Label: label, 308 | } 309 | } 310 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/client.go: -------------------------------------------------------------------------------- 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 | "errors" 21 | "fmt" 22 | "io" 23 | "io/ioutil" 24 | "mime/multipart" 25 | "net/http" 26 | "net/textproto" 27 | "net/url" 28 | "path" 29 | "time" 30 | ) 31 | 32 | // APIEndpoint constants 33 | const ( 34 | APIEndpointBase = "https://api.line.me" 35 | APIEndpointBaseData = "https://api-data.line.me" 36 | 37 | APIEndpointPushMessage = "/v2/bot/message/push" 38 | APIEndpointBroadcastMessage = "/v2/bot/message/broadcast" 39 | APIEndpointReplyMessage = "/v2/bot/message/reply" 40 | APIEndpointMulticast = "/v2/bot/message/multicast" 41 | APIEndpointNarrowcast = "/v2/bot/message/narrowcast" 42 | APIEndpointGetMessageContent = "/v2/bot/message/%s/content" 43 | APIEndpointGetMessageQuota = "/v2/bot/message/quota" 44 | APIEndpointGetMessageConsumption = "/v2/bot/message/quota/consumption" 45 | APIEndpointGetMessageQuotaConsumption = "/v2/bot/message/quota/consumption" 46 | APIEndpointLeaveGroup = "/v2/bot/group/%s/leave" 47 | APIEndpointLeaveRoom = "/v2/bot/room/%s/leave" 48 | APIEndpointGetProfile = "/v2/bot/profile/%s" 49 | APIEndpointGetFollowerIDs = "/v2/bot/followers/ids" 50 | APIEndpointGetGroupMemberProfile = "/v2/bot/group/%s/member/%s" 51 | APIEndpointGetRoomMemberProfile = "/v2/bot/room/%s/member/%s" 52 | APIEndpointGetGroupMemberIDs = "/v2/bot/group/%s/members/ids" 53 | APIEndpointGetRoomMemberIDs = "/v2/bot/room/%s/members/ids" 54 | APIEndpointGetGroupMemberCount = "/v2/bot/group/%s/members/count" 55 | APIEndpointGetRoomMemberCount = "/v2/bot/room/%s/members/count" 56 | APIEndpointGetGroupSummary = "/v2/bot/group/%s/summary" 57 | APIEndpointCreateRichMenu = "/v2/bot/richmenu" 58 | APIEndpointGetRichMenu = "/v2/bot/richmenu/%s" 59 | APIEndpointListRichMenu = "/v2/bot/richmenu/list" 60 | APIEndpointDeleteRichMenu = "/v2/bot/richmenu/%s" 61 | APIEndpointGetUserRichMenu = "/v2/bot/user/%s/richmenu" 62 | APIEndpointLinkUserRichMenu = "/v2/bot/user/%s/richmenu/%s" 63 | APIEndpointUnlinkUserRichMenu = "/v2/bot/user/%s/richmenu" 64 | APIEndpointSetDefaultRichMenu = "/v2/bot/user/all/richmenu/%s" 65 | APIEndpointDefaultRichMenu = "/v2/bot/user/all/richmenu" // Get: GET / Delete: DELETE 66 | APIEndpointDownloadRichMenuImage = "/v2/bot/richmenu/%s/content" // Download: GET / Upload: POST 67 | APIEndpointUploadRichMenuImage = "/v2/bot/richmenu/%s/content" // Download: GET / Upload: POST 68 | APIEndpointBulkLinkRichMenu = "/v2/bot/richmenu/bulk/link" 69 | APIEndpointBulkUnlinkRichMenu = "/v2/bot/richmenu/bulk/unlink" 70 | 71 | APIEndpointCreateRichMenuAlias = "/v2/bot/richmenu/alias" 72 | APIEndpointGetRichMenuAlias = "/v2/bot/richmenu/alias/%s" 73 | APIEndpointUpdateRichMenuAlias = "/v2/bot/richmenu/alias/%s" 74 | APIEndpointDeleteRichMenuAlias = "/v2/bot/richmenu/alias/%s" 75 | APIEndpointListRichMenuAlias = "/v2/bot/richmenu/alias/list" 76 | 77 | APIEndpointGetAllLIFFApps = "/liff/v1/apps" 78 | APIEndpointAddLIFFApp = "/liff/v1/apps" 79 | APIEndpointUpdateLIFFApp = "/liff/v1/apps/%s/view" 80 | APIEndpointDeleteLIFFApp = "/liff/v1/apps/%s" 81 | 82 | APIEndpointLinkToken = "/v2/bot/user/%s/linkToken" 83 | 84 | APIEndpointGetMessageDelivery = "/v2/bot/message/delivery/%s" 85 | APIEndpointGetMessageProgress = "/v2/bot/message/progress/%s" 86 | APIEndpointInsight = "/v2/bot/insight/%s" 87 | APIEndpointGetBotInfo = "/v2/bot/info" 88 | 89 | APIEndpointIssueAccessToken = "/v2/oauth/accessToken" 90 | APIEndpointRevokeAccessToken = "/v2/oauth/revoke" 91 | 92 | APIEndpointIssueAccessTokenV2 = "/oauth2/v2.1/token" 93 | APIEndpointGetAccessTokensV2 = "/oauth2/v2.1/tokens/kid" 94 | APIEndpointRevokeAccessTokenV2 = "/oauth2/v2.1/revoke" 95 | 96 | APIEndpointGetWebhookInfo = "/v2/bot/channel/webhook/endpoint" 97 | APIEndpointSetWebhookEndpoint = "/v2/bot/channel/webhook/endpoint" 98 | APIEndpointTestWebhook = "/v2/bot/channel/webhook/test" 99 | 100 | APIAudienceGroupUpload = "/v2/bot/audienceGroup/upload" 101 | APIAudienceGroupUploadByFile = "/v2/bot/audienceGroup/upload/byFile" 102 | APIAudienceGroupClick = "/v2/bot/audienceGroup/click" 103 | APIAudienceGroupIMP = "/v2/bot/audienceGroup/imp" 104 | APIAudienceGroupUpdateDescription = "/v2/bot/audienceGroup/%d/updateDescription" 105 | APIAudienceGroupActivate = "/v2/bot/audienceGroup/%d/activate" 106 | APIAudienceGroup = "/v2/bot/audienceGroup/%d" 107 | APIAudienceGroupList = "/v2/bot/audienceGroup/list" 108 | APIAudienceGroupAuthorityLevel = "/v2/bot/audienceGroup/authorityLevel" 109 | ) 110 | 111 | // Client type 112 | type Client struct { 113 | channelSecret string 114 | channelToken string 115 | endpointBase *url.URL // default APIEndpointBase 116 | endpointBaseData *url.URL // default APIEndpointBaseData 117 | httpClient *http.Client // default http.DefaultClient 118 | retryKeyID string // X-Line-Retry-Key allows you to safely retry API requests without duplicating messages 119 | } 120 | 121 | // ClientOption type 122 | type ClientOption func(*Client) error 123 | 124 | // New returns a new bot client instance. 125 | func New(channelSecret, channelToken string, options ...ClientOption) (*Client, error) { 126 | if channelSecret == "" { 127 | return nil, errors.New("missing channel secret") 128 | } 129 | if channelToken == "" { 130 | return nil, errors.New("missing channel access token") 131 | } 132 | c := &Client{ 133 | channelSecret: channelSecret, 134 | channelToken: channelToken, 135 | httpClient: http.DefaultClient, 136 | } 137 | for _, option := range options { 138 | err := option(c) 139 | if err != nil { 140 | return nil, err 141 | } 142 | } 143 | if c.endpointBase == nil { 144 | u, err := url.ParseRequestURI(APIEndpointBase) 145 | if err != nil { 146 | return nil, err 147 | } 148 | c.endpointBase = u 149 | } 150 | if c.endpointBaseData == nil { 151 | u, err := url.ParseRequestURI(APIEndpointBaseData) 152 | if err != nil { 153 | return nil, err 154 | } 155 | c.endpointBaseData = u 156 | } 157 | return c, nil 158 | } 159 | 160 | // WithHTTPClient function 161 | func WithHTTPClient(c *http.Client) ClientOption { 162 | return func(client *Client) error { 163 | client.httpClient = c 164 | return nil 165 | } 166 | } 167 | 168 | // WithEndpointBase function 169 | func WithEndpointBase(endpointBase string) ClientOption { 170 | return func(client *Client) error { 171 | u, err := url.ParseRequestURI(endpointBase) 172 | if err != nil { 173 | return err 174 | } 175 | client.endpointBase = u 176 | return nil 177 | } 178 | } 179 | 180 | // WithEndpointBaseData function 181 | func WithEndpointBaseData(endpointBaseData string) ClientOption { 182 | return func(client *Client) error { 183 | u, err := url.ParseRequestURI(endpointBaseData) 184 | if err != nil { 185 | return err 186 | } 187 | client.endpointBaseData = u 188 | return nil 189 | } 190 | } 191 | 192 | func (client *Client) url(base *url.URL, endpoint string) string { 193 | u := *base 194 | u.Path = path.Join(u.Path, endpoint) 195 | return u.String() 196 | } 197 | 198 | func (client *Client) do(ctx context.Context, req *http.Request) (*http.Response, error) { 199 | req.Header.Set("Authorization", "Bearer "+client.channelToken) 200 | req.Header.Set("User-Agent", "LINE-BotSDK-Go/"+version) 201 | if len(client.retryKeyID) > 0 { 202 | req.Header.Set("X-Line-Retry-Key", client.retryKeyID) 203 | } 204 | if ctx != nil { 205 | req = req.WithContext(ctx) 206 | } 207 | return client.httpClient.Do(req) 208 | } 209 | 210 | func (client *Client) get(ctx context.Context, base *url.URL, endpoint string, query url.Values) (*http.Response, error) { 211 | req, err := http.NewRequest(http.MethodGet, client.url(base, endpoint), nil) 212 | if err != nil { 213 | return nil, err 214 | } 215 | if query != nil { 216 | req.URL.RawQuery = query.Encode() 217 | } 218 | return client.do(ctx, req) 219 | } 220 | 221 | func (client *Client) post(ctx context.Context, endpoint string, body io.Reader) (*http.Response, error) { 222 | req, err := http.NewRequest(http.MethodPost, client.url(client.endpointBase, endpoint), body) 223 | if err != nil { 224 | return nil, err 225 | } 226 | req.Header.Set("Content-Type", "application/json; charset=UTF-8") 227 | return client.do(ctx, req) 228 | } 229 | 230 | func (client *Client) postForm(ctx context.Context, endpoint string, body io.Reader) (*http.Response, error) { 231 | req, err := http.NewRequest("POST", client.url(client.endpointBase, endpoint), body) 232 | if err != nil { 233 | return nil, err 234 | } 235 | req.Header.Set("Content-Type", "application/x-www-form-urlencoded") 236 | return client.do(ctx, req) 237 | } 238 | 239 | func (client *Client) postFormFile(ctx context.Context, endpoint string, values map[string]io.Reader) (*http.Response, error) { 240 | b, contentType, err := uploadFile(values) 241 | if err != nil { 242 | return nil, err 243 | } 244 | req, err := http.NewRequest(http.MethodPost, client.url(client.endpointBaseData, endpoint), &b) 245 | if err != nil { 246 | return nil, err 247 | } 248 | req.Header.Set("Content-Type", contentType) 249 | return client.do(ctx, req) 250 | } 251 | 252 | func (client *Client) put(ctx context.Context, endpoint string, body io.Reader) (*http.Response, error) { 253 | req, err := http.NewRequest(http.MethodPut, client.url(client.endpointBase, endpoint), body) 254 | if err != nil { 255 | return nil, err 256 | } 257 | req.Header.Set("Content-Type", "application/json; charset=UTF-8") 258 | return client.do(ctx, req) 259 | } 260 | 261 | func (client *Client) putFormFile(ctx context.Context, endpoint string, values map[string]io.Reader) (*http.Response, error) { 262 | b, contentType, err := uploadFile(values) 263 | if err != nil { 264 | return nil, err 265 | } 266 | req, err := http.NewRequest(http.MethodPut, client.url(client.endpointBaseData, endpoint), &b) 267 | if err != nil { 268 | return nil, err 269 | } 270 | req.Header.Set("Content-Type", contentType) 271 | return client.do(ctx, req) 272 | } 273 | 274 | func (client *Client) delete(ctx context.Context, endpoint string) (*http.Response, error) { 275 | req, err := http.NewRequest(http.MethodDelete, client.url(client.endpointBase, endpoint), nil) 276 | if err != nil { 277 | return nil, err 278 | } 279 | return client.do(ctx, req) 280 | } 281 | 282 | func (client *Client) setRetryKey(retryKey string) { 283 | client.retryKeyID = retryKey 284 | } 285 | 286 | func closeResponse(res *http.Response) error { 287 | defer res.Body.Close() 288 | _, err := io.Copy(ioutil.Discard, res.Body) 289 | return err 290 | } 291 | 292 | func uploadFile(values map[string]io.Reader) (bytes.Buffer, string, error) { 293 | var ( 294 | b bytes.Buffer 295 | err error 296 | ) 297 | w := multipart.NewWriter(&b) 298 | for key, r := range values { 299 | var fw io.Writer 300 | if x, ok := r.(io.Closer); ok { 301 | defer x.Close() 302 | } 303 | if _, ok := r.(*bytes.Buffer); ok { 304 | h := make(textproto.MIMEHeader) 305 | h.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s.txt"`, key, time.Now().Format("20060102150405"))) 306 | h.Set("Content-Type", "text/plain") 307 | if fw, err = w.CreatePart(h); err != nil { 308 | return b, "", err 309 | } 310 | } else { 311 | if fw, err = w.CreateFormField(key); err != nil { 312 | return b, "", err 313 | } 314 | } 315 | if _, err := io.Copy(fw, r); err != nil { 316 | return b, "", err 317 | } 318 | } 319 | w.Close() 320 | return b, w.FormDataContentType(), nil 321 | } 322 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/content_provider.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // ContentProviderType type 18 | type ContentProviderType string 19 | 20 | // ContentProviderType constants 21 | const ( 22 | ContentProviderTypeLINE ContentProviderType = "line" 23 | ContentProviderTypeExternal ContentProviderType = "external" 24 | ) 25 | 26 | // ContentProvider type 27 | type ContentProvider struct { 28 | Type ContentProviderType `json:"type"` 29 | OriginalContentURL string `json:"originalContentUrl,omitempty"` 30 | PreviewImageURL string `json:"previewImageUrl,omitempty"` 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/delivery.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | "context" 19 | "fmt" 20 | "net/url" 21 | ) 22 | 23 | // DeliveryType type 24 | type DeliveryType string 25 | 26 | // DeliveryType constants 27 | const ( 28 | DeliveryTypeMulticast DeliveryType = "multicast" 29 | DeliveryTypePush DeliveryType = "push" 30 | DeliveryTypeReply DeliveryType = "reply" 31 | DeliveryTypeBroadcast DeliveryType = "broadcast" 32 | ) 33 | 34 | // GetNumberReplyMessages method 35 | func (client *Client) GetNumberReplyMessages(date string) *GetNumberMessagesCall { 36 | return &GetNumberMessagesCall{ 37 | c: client, 38 | date: date, 39 | deliveryType: DeliveryTypeReply, 40 | } 41 | } 42 | 43 | // GetNumberPushMessages method 44 | func (client *Client) GetNumberPushMessages(date string) *GetNumberMessagesCall { 45 | return &GetNumberMessagesCall{ 46 | c: client, 47 | date: date, 48 | deliveryType: DeliveryTypePush, 49 | } 50 | } 51 | 52 | // GetNumberMulticastMessages method 53 | func (client *Client) GetNumberMulticastMessages(date string) *GetNumberMessagesCall { 54 | return &GetNumberMessagesCall{ 55 | c: client, 56 | date: date, 57 | deliveryType: DeliveryTypeMulticast, 58 | } 59 | } 60 | 61 | // GetNumberBroadcastMessages method 62 | func (client *Client) GetNumberBroadcastMessages(date string) *GetNumberMessagesCall { 63 | return &GetNumberMessagesCall{ 64 | c: client, 65 | date: date, 66 | deliveryType: DeliveryTypeBroadcast, 67 | } 68 | } 69 | 70 | // GetNumberMessagesCall type 71 | type GetNumberMessagesCall struct { 72 | c *Client 73 | ctx context.Context 74 | 75 | date string 76 | deliveryType DeliveryType 77 | } 78 | 79 | // WithContext method 80 | func (call *GetNumberMessagesCall) WithContext(ctx context.Context) *GetNumberMessagesCall { 81 | call.ctx = ctx 82 | return call 83 | } 84 | 85 | // Do method 86 | func (call *GetNumberMessagesCall) Do() (*MessagesNumberResponse, error) { 87 | endpoint := fmt.Sprintf(APIEndpointGetMessageDelivery, call.deliveryType) 88 | var q url.Values 89 | if call.date != "" { 90 | q = url.Values{"date": []string{call.date}} 91 | } 92 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q) 93 | if err != nil { 94 | return nil, err 95 | } 96 | defer closeResponse(res) 97 | return decodeToMessagesNumberResponse(res) 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/demographic_filter.go: -------------------------------------------------------------------------------- 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 | // DemographicFilter interface 20 | type DemographicFilter interface { 21 | DemographicFilter() 22 | } 23 | 24 | // GenderType type 25 | type GenderType string 26 | 27 | // GenderType constants 28 | const ( 29 | GenderMale GenderType = "male" 30 | GenderFemale GenderType = "female" 31 | ) 32 | 33 | // GenderFilter type 34 | type GenderFilter struct { 35 | Type string `json:"type"` 36 | Genders []GenderType `json:"oneOf"` 37 | } 38 | 39 | // NewGenderFilter function 40 | func NewGenderFilter(genders ...GenderType) *GenderFilter { 41 | return &GenderFilter{ 42 | Type: "gender", 43 | Genders: genders, 44 | } 45 | } 46 | 47 | // DemographicFilter implements DemographicFilter interface 48 | func (*GenderFilter) DemographicFilter() {} 49 | 50 | // AgeType type 51 | type AgeType string 52 | 53 | // AgeType constants 54 | const ( 55 | AgeEmpty AgeType = "" 56 | Age15 AgeType = "age_15" 57 | Age20 AgeType = "age_20" 58 | Age25 AgeType = "age_25" 59 | Age30 AgeType = "age_30" 60 | Age35 AgeType = "age_35" 61 | Age40 AgeType = "age_40" 62 | Age45 AgeType = "age_45" 63 | Age50 AgeType = "age_50" 64 | ) 65 | 66 | // AgeFilter type 67 | type AgeFilter struct { 68 | Type string `json:"type"` 69 | GTE AgeType `json:"gte,omitempty"` // greater than or equal to 70 | LT AgeType `json:"lt,omitempty"` // less than 71 | } 72 | 73 | // NewAgeFilter function 74 | func NewAgeFilter(gte, lt AgeType) *AgeFilter { 75 | return &AgeFilter{ 76 | Type: "age", 77 | GTE: gte, 78 | LT: lt, 79 | } 80 | } 81 | 82 | // DemographicFilter implements DemographicFilter interface 83 | func (*AgeFilter) DemographicFilter() {} 84 | 85 | // AppType type 86 | type AppType string 87 | 88 | // AppType constants 89 | const ( 90 | AppTypeIOS AppType = "ios" 91 | AppTypeAndroid AppType = "android" 92 | ) 93 | 94 | // AppTypeFilter type 95 | type AppTypeFilter struct { 96 | Type string `json:"type"` 97 | AppTypes []AppType `json:"oneOf"` 98 | } 99 | 100 | // NewAppTypeFilter function 101 | func NewAppTypeFilter(appTypes ...AppType) *AppTypeFilter { 102 | return &AppTypeFilter{ 103 | Type: "appType", 104 | AppTypes: appTypes, 105 | } 106 | } 107 | 108 | // DemographicFilter implements DemographicFilter interface 109 | func (*AppTypeFilter) DemographicFilter() {} 110 | 111 | // AreaType type 112 | type AreaType string 113 | 114 | // AreaType constants 115 | const ( 116 | AreaJPHokkaido AreaType = "jp_01" 117 | AreaJPAomori AreaType = "jp_02" 118 | AreaJPIwate AreaType = "jp_03" 119 | AreaJPMiyagi AreaType = "jp_04" 120 | AreaJPAkita AreaType = "jp_05" 121 | AreaJPYamagata AreaType = "jp_06" 122 | AreaJPFukushima AreaType = "jp_07" 123 | AreaJPIbaraki AreaType = "jp_08" 124 | AreaJPTochigi AreaType = "jp_09" 125 | AreaJPGunma AreaType = "jp_10" 126 | AreaJPSaitama AreaType = "jp_11" 127 | AreaJPChiba AreaType = "jp_12" 128 | AreaJPTokyo AreaType = "jp_13" 129 | AreaJPKanagawa AreaType = "jp_14" 130 | AreaJPNiigata AreaType = "jp_15" 131 | AreaJPToyama AreaType = "jp_16" 132 | AreaJPIshikawa AreaType = "jp_17" 133 | AreaJPFukui AreaType = "jp_18" 134 | AreaJPYamanashi AreaType = "jp_19" 135 | AreaJPNagano AreaType = "jp_20" 136 | AreaJPGifu AreaType = "jp_21" 137 | AreaJPShizuoka AreaType = "jp_22" 138 | AreaJPAichi AreaType = "jp_23" 139 | AreaJPMie AreaType = "jp_24" 140 | AreaJPShiga AreaType = "jp_25" 141 | AreaJPKyoto AreaType = "jp_26" 142 | AreaJPOsaka AreaType = "jp_27" 143 | AreaJPHyougo AreaType = "jp_28" 144 | AreaJPNara AreaType = "jp_29" 145 | AreaJPWakayama AreaType = "jp_30" 146 | AreaJPTottori AreaType = "jp_31" 147 | AreaJPShimane AreaType = "jp_32" 148 | AreaJPOkayama AreaType = "jp_33" 149 | AreaJPHiroshima AreaType = "jp_34" 150 | AreaJPYamaguchi AreaType = "jp_35" 151 | AreaJPTokushima AreaType = "jp_36" 152 | AreaJPKagawa AreaType = "jp_37" 153 | AreaJPEhime AreaType = "jp_38" 154 | AreaJPKouchi AreaType = "jp_39" 155 | AreaJPFukuoka AreaType = "jp_40" 156 | AreaJPSaga AreaType = "jp_41" 157 | AreaJPNagasaki AreaType = "jp_42" 158 | AreaJPKumamoto AreaType = "jp_43" 159 | AreaJPOita AreaType = "jp_44" 160 | AreaJPMiyazaki AreaType = "jp_45" 161 | AreaJPKagoshima AreaType = "jp_46" 162 | AreaJPOkinawa AreaType = "jp_47" 163 | AreaTWTaipeiCity AreaType = "tw_01" 164 | AreaTWNewTaipeiCity AreaType = "tw_02" 165 | AreaTWTaoyuanCity AreaType = "tw_03" 166 | AreaTWTaichungCity AreaType = "tw_04" 167 | AreaTWTainanCity AreaType = "tw_05" 168 | AreaTWKaohsiungCity AreaType = "tw_06" 169 | AreaTWKeelungCity AreaType = "tw_07" 170 | AreaTWHsinchuCity AreaType = "tw_08" 171 | AreaTWChiayiCity AreaType = "tw_09" 172 | AreaTWHsinchuCounty AreaType = "tw_10" 173 | AreaTWMiaoliCounty AreaType = "tw_11" 174 | AreaTWChanghuaCounty AreaType = "tw_12" 175 | AreaTWNantouCounty AreaType = "tw_13" 176 | AreaTWYunlinCounty AreaType = "tw_14" 177 | AreaTWChiayiCounty AreaType = "tw_15" 178 | AreaTWPingtungCounty AreaType = "tw_16" 179 | AreaTWYilanCounty AreaType = "tw_17" 180 | AreaTWHualienCounty AreaType = "tw_18" 181 | AreaTWTaitungCounty AreaType = "tw_19" 182 | AreaTWPenghuCounty AreaType = "tw_20" 183 | AreaTWKinmenCounty AreaType = "tw_21" 184 | AreaTWLienchiangCounty AreaType = "tw_22" 185 | AreaTHBangkok AreaType = "th_01" 186 | AreaTHPattaya AreaType = "th_02" 187 | AreaTHNorthern AreaType = "th_03" 188 | AreaTHCentral AreaType = "th_04" 189 | AreaTHSouthern AreaType = "th_05" 190 | AreaTHEastern AreaType = "th_06" 191 | AreaTHNorthEastern AreaType = "th_07" 192 | AreaTHWestern AreaType = "th_08" 193 | AreaIDBali AreaType = "id_01" 194 | AreaIDBandung AreaType = "id_02" 195 | AreaIDBanjarmasin AreaType = "id_03" 196 | AreaIDJabodetabek AreaType = "id_04" 197 | AreaIDLainnya AreaType = "id_05" 198 | AreaIDMakassar AreaType = "id_06" 199 | AreaIDMedan AreaType = "id_07" 200 | AreaIDPalembang AreaType = "id_08" 201 | AreaIDSamarinda AreaType = "id_09" 202 | AreaIDSemarang AreaType = "id_10" 203 | AreaIDSurabaya AreaType = "id_11" 204 | AreaIDYogyakarta AreaType = "id_12" 205 | ) 206 | 207 | // AreaFilter type 208 | type AreaFilter struct { 209 | Type string `json:"type"` 210 | Areas []AreaType `json:"oneOf"` 211 | } 212 | 213 | // NewAreaFilter function 214 | func NewAreaFilter(areaTypes ...AreaType) *AreaFilter { 215 | return &AreaFilter{ 216 | Type: "area", 217 | Areas: areaTypes, 218 | } 219 | } 220 | 221 | // DemographicFilter implements DemographicFilter interface 222 | func (*AreaFilter) DemographicFilter() {} 223 | 224 | // PeriodType type 225 | type PeriodType string 226 | 227 | // PeriodType constants 228 | const ( 229 | PeriodEmpty PeriodType = "" 230 | PeriodDay7 PeriodType = "day_7" 231 | PeriodDay30 PeriodType = "day_30" 232 | PeriodDay90 PeriodType = "day_90" 233 | PeriodDay180 PeriodType = "day_180" 234 | PeriodDay365 PeriodType = "day_365" 235 | ) 236 | 237 | // SubscriptionPeriodFilter type 238 | type SubscriptionPeriodFilter struct { 239 | Type string `json:"type"` 240 | GTE PeriodType `json:"gte,omitempty"` // greater than or equal to 241 | LT PeriodType `json:"lt,omitempty"` // less than 242 | } 243 | 244 | // NewSubscriptionPeriodFilter function 245 | func NewSubscriptionPeriodFilter(gte, lt PeriodType) *SubscriptionPeriodFilter { 246 | return &SubscriptionPeriodFilter{ 247 | Type: "subscriptionPeriod", 248 | GTE: gte, 249 | LT: lt, 250 | } 251 | } 252 | 253 | // DemographicFilter implements DemographicFilter interface 254 | func (*SubscriptionPeriodFilter) DemographicFilter() {} 255 | 256 | // DemographicFilterOperator struct 257 | type DemographicFilterOperator struct { 258 | ConditionAnd []DemographicFilter `json:"and,omitempty"` 259 | ConditionOr []DemographicFilter `json:"or,omitempty"` 260 | ConditionNot DemographicFilter `json:"not,omitempty"` 261 | } 262 | 263 | // DemographicFilterOperatorAnd method 264 | func DemographicFilterOperatorAnd(conditions ...DemographicFilter) *DemographicFilterOperator { 265 | return &DemographicFilterOperator{ 266 | ConditionAnd: conditions, 267 | } 268 | } 269 | 270 | // DemographicFilterOperatorOr method 271 | func DemographicFilterOperatorOr(conditions ...DemographicFilter) *DemographicFilterOperator { 272 | return &DemographicFilterOperator{ 273 | ConditionOr: conditions, 274 | } 275 | } 276 | 277 | // DemographicFilterOperatorNot method 278 | func DemographicFilterOperatorNot(condition DemographicFilter) *DemographicFilterOperator { 279 | return &DemographicFilterOperator{ 280 | ConditionNot: condition, 281 | } 282 | } 283 | 284 | // MarshalJSON method of DemographicFilterOperator 285 | func (o *DemographicFilterOperator) MarshalJSON() ([]byte, error) { 286 | return json.Marshal(&struct { 287 | Type string `json:"type"` 288 | ConditionAnd []DemographicFilter `json:"and,omitempty"` 289 | ConditionOr []DemographicFilter `json:"or,omitempty"` 290 | ConditionNot DemographicFilter `json:"not,omitempty"` 291 | }{ 292 | Type: "operator", 293 | ConditionAnd: o.ConditionAnd, 294 | ConditionOr: o.ConditionOr, 295 | ConditionNot: o.ConditionNot, 296 | }) 297 | } 298 | 299 | // DemographicFilter implements DemographicFilter interface 300 | func (*DemographicFilterOperator) DemographicFilter() {} 301 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/emoji.go: -------------------------------------------------------------------------------- 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 | // Emoji type 18 | type Emoji struct { 19 | Index int `json:"index"` 20 | Length int `json:"length,omitempty"` 21 | ProductID string `json:"productId,omitempty"` 22 | EmojiID string `json:"emojiId,omitempty"` 23 | } 24 | 25 | // NewEmoji function 26 | func NewEmoji(index int, productID, emojiID string) *Emoji { 27 | return &Emoji{ 28 | Index: index, 29 | ProductID: productID, 30 | EmojiID: emojiID, 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/error.go: -------------------------------------------------------------------------------- 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 | "errors" 20 | "fmt" 21 | ) 22 | 23 | // errors 24 | var ( 25 | ErrInvalidSignature = errors.New("invalid signature") 26 | ) 27 | 28 | // APIError type 29 | type APIError struct { 30 | Code int 31 | Response *ErrorResponse 32 | } 33 | 34 | // Error method 35 | func (e *APIError) Error() string { 36 | var buf bytes.Buffer 37 | fmt.Fprintf(&buf, "linebot: APIError %d ", e.Code) 38 | if e.Response != nil { 39 | fmt.Fprintf(&buf, "%s", e.Response.Message) 40 | for _, d := range e.Response.Details { 41 | fmt.Fprintf(&buf, "\n[%s] %s", d.Property, d.Message) 42 | } 43 | } 44 | return buf.String() 45 | } 46 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/event.go: -------------------------------------------------------------------------------- 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 | "encoding/hex" 19 | "encoding/json" 20 | "time" 21 | ) 22 | 23 | // EventType type 24 | type EventType string 25 | 26 | // EventType constants 27 | const ( 28 | EventTypeMessage EventType = "message" 29 | EventTypeFollow EventType = "follow" 30 | EventTypeUnfollow EventType = "unfollow" 31 | EventTypeJoin EventType = "join" 32 | EventTypeLeave EventType = "leave" 33 | EventTypeMemberJoined EventType = "memberJoined" 34 | EventTypeMemberLeft EventType = "memberLeft" 35 | EventTypePostback EventType = "postback" 36 | EventTypeBeacon EventType = "beacon" 37 | EventTypeAccountLink EventType = "accountLink" 38 | EventTypeThings EventType = "things" 39 | EventTypeUnsend EventType = "unsend" 40 | EventTypeVideoPlayComplete EventType = "videoPlayComplete" 41 | ) 42 | 43 | // EventMode type 44 | type EventMode string 45 | 46 | // EventMode constants 47 | const ( 48 | EventModeActive EventMode = "active" 49 | EventModeStandby EventMode = "standby" 50 | ) 51 | 52 | // EventSourceType type 53 | type EventSourceType string 54 | 55 | // EventSourceType constants 56 | const ( 57 | EventSourceTypeUser EventSourceType = "user" 58 | EventSourceTypeGroup EventSourceType = "group" 59 | EventSourceTypeRoom EventSourceType = "room" 60 | ) 61 | 62 | // EventSource type 63 | type EventSource struct { 64 | Type EventSourceType `json:"type"` 65 | UserID string `json:"userId,omitempty"` 66 | GroupID string `json:"groupId,omitempty"` 67 | RoomID string `json:"roomId,omitempty"` 68 | } 69 | 70 | // Params type 71 | type Params struct { 72 | Date string `json:"date,omitempty"` 73 | Time string `json:"time,omitempty"` 74 | Datetime string `json:"datetime,omitempty"` 75 | NewRichMenuAliasID string `json:"newRichMenuAliasId,omitempty"` 76 | Status string `json:"status,omitempty"` 77 | } 78 | 79 | // Members type 80 | type Members struct { 81 | Members []EventSource `json:"members"` 82 | } 83 | 84 | // Postback type 85 | type Postback struct { 86 | Data string `json:"data"` 87 | Params *Params `json:"params,omitempty"` 88 | } 89 | 90 | // BeaconEventType type 91 | type BeaconEventType string 92 | 93 | // BeaconEventType constants 94 | const ( 95 | BeaconEventTypeEnter BeaconEventType = "enter" 96 | BeaconEventTypeLeave BeaconEventType = "leave" 97 | BeaconEventTypeBanner BeaconEventType = "banner" 98 | BeaconEventTypeStay BeaconEventType = "stay" 99 | ) 100 | 101 | // Beacon type 102 | type Beacon struct { 103 | Hwid string 104 | Type BeaconEventType 105 | DeviceMessage []byte 106 | } 107 | 108 | // AccountLinkResult type 109 | type AccountLinkResult string 110 | 111 | // AccountLinkResult constants 112 | const ( 113 | AccountLinkResultOK AccountLinkResult = "ok" 114 | AccountLinkResultFailed AccountLinkResult = "failed" 115 | ) 116 | 117 | // AccountLink type 118 | type AccountLink struct { 119 | Result AccountLinkResult 120 | Nonce string 121 | } 122 | 123 | // ThingsResult type 124 | type ThingsResult struct { 125 | ScenarioID string 126 | Revision int 127 | StartTime int64 128 | EndTime int64 129 | ResultCode ThingsResultCode 130 | ActionResults []*ThingsActionResult 131 | BLENotificationPayload []byte 132 | ErrorReason string 133 | } 134 | 135 | // ThingsResultCode type 136 | type ThingsResultCode string 137 | 138 | // ThingsResultCode constants 139 | const ( 140 | ThingsResultCodeSuccess ThingsResultCode = "success" 141 | ThingsResultCodeGattError ThingsResultCode = "gatt_error" 142 | ThingsResultCodeRuntimeError ThingsResultCode = "runtime_error" 143 | ) 144 | 145 | // ThingsActionResult type 146 | type ThingsActionResult struct { 147 | Type ThingsActionResultType 148 | Data []byte 149 | } 150 | 151 | // ThingsActionResultType type 152 | type ThingsActionResultType string 153 | 154 | // ThingsActionResultType constants 155 | const ( 156 | ThingsActionResultTypeBinary ThingsActionResultType = "binary" 157 | ThingsActionResultTypeVoid ThingsActionResultType = "void" 158 | ) 159 | 160 | // Things type 161 | type Things struct { 162 | DeviceID string 163 | Type string 164 | Result *ThingsResult 165 | } 166 | 167 | // Unsend type 168 | type Unsend struct { 169 | MessageID string `json:"messageId"` 170 | } 171 | 172 | // VideoPlayComplete type 173 | type VideoPlayComplete struct { 174 | TrackingID string `json:"trackingId"` 175 | } 176 | 177 | // StickerResourceType type 178 | type StickerResourceType string 179 | 180 | // StickerResourceType constants 181 | const ( 182 | StickerResourceTypeStatic StickerResourceType = "STATIC" 183 | StickerResourceTypeAnimation StickerResourceType = "ANIMATION" 184 | StickerResourceTypeSound StickerResourceType = "SOUND" 185 | StickerResourceTypeAnimationSound StickerResourceType = "ANIMATION_SOUND" 186 | StickerResourceTypePerStickerText StickerResourceType = "MESSAGE" 187 | StickerResourceTypePopup StickerResourceType = "POPUP" 188 | StickerResourceTypePopupSound StickerResourceType = "POPUP_SOUND" 189 | StickerResourceTypeNameText StickerResourceType = "CUSTOM" 190 | ) 191 | 192 | // DeliveryContext type 193 | type DeliveryContext struct { 194 | IsRedelivery bool `json:"isRedelivery"` 195 | } 196 | 197 | // Event type 198 | type Event struct { 199 | ReplyToken string 200 | Type EventType 201 | Mode EventMode 202 | Timestamp time.Time 203 | Source *EventSource 204 | Message Message 205 | Joined *Members 206 | Left *Members 207 | Postback *Postback 208 | Beacon *Beacon 209 | AccountLink *AccountLink 210 | Things *Things 211 | Members []*EventSource 212 | Unsend *Unsend 213 | VideoPlayComplete *VideoPlayComplete 214 | WebhookEventID string 215 | DeliveryContext DeliveryContext 216 | } 217 | 218 | type rawEvent struct { 219 | ReplyToken string `json:"replyToken,omitempty"` 220 | Type EventType `json:"type"` 221 | Mode EventMode `json:"mode"` 222 | Timestamp int64 `json:"timestamp"` 223 | Source *EventSource `json:"source"` 224 | Message *rawEventMessage `json:"message,omitempty"` 225 | Postback *Postback `json:"postback,omitempty"` 226 | Beacon *rawBeaconEvent `json:"beacon,omitempty"` 227 | AccountLink *rawAccountLinkEvent `json:"link,omitempty"` 228 | Joined *rawMemberEvent `json:"joined,omitempty"` 229 | Left *rawMemberEvent `json:"left,omitempty"` 230 | Things *rawThingsEvent `json:"things,omitempty"` 231 | Unsend *Unsend `json:"unsend,omitempty"` 232 | VideoPlayComplete *VideoPlayComplete `json:"videoPlayComplete,omitempty"` 233 | WebhookEventID string `json:"webhookEventId"` 234 | DeliveryContext DeliveryContext `json:"deliveryContext"` 235 | } 236 | 237 | type rawMemberEvent struct { 238 | Members []*EventSource `json:"members"` 239 | } 240 | 241 | type rawEventMessage struct { 242 | ID string `json:"id"` 243 | Type MessageType `json:"type"` 244 | Text string `json:"text,omitempty"` 245 | Duration int `json:"duration,omitempty"` 246 | Title string `json:"title,omitempty"` 247 | Address string `json:"address,omitempty"` 248 | FileName string `json:"fileName,omitempty"` 249 | FileSize int `json:"fileSize,omitempty"` 250 | Latitude float64 `json:"latitude,omitempty"` 251 | Longitude float64 `json:"longitude,omitempty"` 252 | PackageID string `json:"packageId,omitempty"` 253 | StickerID string `json:"stickerId,omitempty"` 254 | ContentProvider *ContentProvider `json:"contentProvider,omitempty"` 255 | ImageSet *ImageSet `json:"imageSet,omitempty"` 256 | StickerResourceType StickerResourceType `json:"stickerResourceType,omitempty"` 257 | Keywords []string `json:"keywords,omitempty"` 258 | Emojis []*Emoji `json:"emojis,omitempty"` 259 | Mention *Mention `json:"mention,omitempty"` 260 | } 261 | 262 | type rawBeaconEvent struct { 263 | Hwid string `json:"hwid"` 264 | Type BeaconEventType `json:"type"` 265 | DM string `json:"dm,omitempty"` 266 | } 267 | 268 | type rawAccountLinkEvent struct { 269 | Result AccountLinkResult `json:"result"` 270 | Nonce string `json:"nonce"` 271 | } 272 | 273 | type rawThingsResult struct { 274 | ScenarioID string `json:"scenarioId"` 275 | Revision int `json:"revision"` 276 | StartTime int64 `json:"startTime"` 277 | EndTime int64 `json:"endTime"` 278 | ResultCode ThingsResultCode `json:"resultCode"` 279 | ActionResults []*rawThingsActionResult `json:"actionResults"` 280 | BLENotificationPayload string `json:"bleNotificationPayload,omitempty"` 281 | ErrorReason string `json:"errorReason,omitempty"` 282 | } 283 | 284 | type rawThingsActionResult struct { 285 | Type ThingsActionResultType `json:"type,omitempty"` 286 | Data string `json:"data,omitempty"` 287 | } 288 | 289 | type rawThingsEvent struct { 290 | DeviceID string `json:"deviceId"` 291 | Type string `json:"type"` 292 | Result *rawThingsResult `json:"result,omitempty"` 293 | } 294 | 295 | const ( 296 | milliSecPerSec = int64(time.Second / time.Millisecond) 297 | nanoSecPerMilliSec = int64(time.Millisecond / time.Nanosecond) 298 | ) 299 | 300 | // MarshalJSON method of Event 301 | func (e *Event) MarshalJSON() ([]byte, error) { 302 | raw := rawEvent{ 303 | ReplyToken: e.ReplyToken, 304 | Type: e.Type, 305 | Mode: e.Mode, 306 | Timestamp: e.Timestamp.Unix()*milliSecPerSec + int64(e.Timestamp.Nanosecond())/int64(time.Millisecond), 307 | Source: e.Source, 308 | Postback: e.Postback, 309 | Unsend: e.Unsend, 310 | VideoPlayComplete: e.VideoPlayComplete, 311 | WebhookEventID: e.WebhookEventID, 312 | DeliveryContext: e.DeliveryContext, 313 | } 314 | if e.Beacon != nil { 315 | raw.Beacon = &rawBeaconEvent{ 316 | Hwid: e.Beacon.Hwid, 317 | Type: e.Beacon.Type, 318 | DM: hex.EncodeToString(e.Beacon.DeviceMessage), 319 | } 320 | } 321 | if e.AccountLink != nil { 322 | raw.AccountLink = &rawAccountLinkEvent{ 323 | Result: e.AccountLink.Result, 324 | Nonce: e.AccountLink.Nonce, 325 | } 326 | } 327 | 328 | switch e.Type { 329 | case EventTypeMemberJoined: 330 | raw.Joined = &rawMemberEvent{ 331 | Members: e.Members, 332 | } 333 | case EventTypeMemberLeft: 334 | raw.Left = &rawMemberEvent{ 335 | Members: e.Members, 336 | } 337 | case EventTypeThings: 338 | raw.Things = &rawThingsEvent{ 339 | DeviceID: e.Things.DeviceID, 340 | Type: e.Things.Type, 341 | } 342 | if e.Things.Result != nil { 343 | raw.Things.Result = &rawThingsResult{ 344 | ScenarioID: e.Things.Result.ScenarioID, 345 | Revision: e.Things.Result.Revision, 346 | StartTime: e.Things.Result.StartTime, 347 | EndTime: e.Things.Result.EndTime, 348 | ResultCode: e.Things.Result.ResultCode, 349 | 350 | BLENotificationPayload: string(e.Things.Result.BLENotificationPayload), 351 | ErrorReason: e.Things.Result.ErrorReason, 352 | } 353 | if e.Things.Result.ActionResults != nil { 354 | raw.Things.Result.ActionResults = make([]*rawThingsActionResult, len(e.Things.Result.ActionResults)) 355 | } 356 | for i := range e.Things.Result.ActionResults { 357 | raw.Things.Result.ActionResults[i] = &rawThingsActionResult{ 358 | Type: e.Things.Result.ActionResults[i].Type, 359 | Data: string(e.Things.Result.ActionResults[i].Data), 360 | } 361 | } 362 | } 363 | } 364 | 365 | switch m := e.Message.(type) { 366 | case *TextMessage: 367 | raw.Message = &rawEventMessage{ 368 | Type: MessageTypeText, 369 | ID: m.ID, 370 | Text: m.Text, 371 | Emojis: m.Emojis, 372 | Mention: m.Mention, 373 | } 374 | case *ImageMessage: 375 | raw.Message = &rawEventMessage{ 376 | Type: MessageTypeImage, 377 | ID: m.ID, 378 | ContentProvider: m.ContentProvider, 379 | ImageSet: m.ImageSet, 380 | } 381 | case *VideoMessage: 382 | raw.Message = &rawEventMessage{ 383 | Type: MessageTypeVideo, 384 | ID: m.ID, 385 | Duration: m.Duration, 386 | ContentProvider: m.ContentProvider, 387 | } 388 | case *AudioMessage: 389 | raw.Message = &rawEventMessage{ 390 | Type: MessageTypeAudio, 391 | ID: m.ID, 392 | Duration: m.Duration, 393 | ContentProvider: m.ContentProvider, 394 | } 395 | case *FileMessage: 396 | raw.Message = &rawEventMessage{ 397 | Type: MessageTypeFile, 398 | ID: m.ID, 399 | FileName: m.FileName, 400 | FileSize: m.FileSize, 401 | } 402 | case *LocationMessage: 403 | raw.Message = &rawEventMessage{ 404 | Type: MessageTypeLocation, 405 | ID: m.ID, 406 | Title: m.Title, 407 | Address: m.Address, 408 | Latitude: m.Latitude, 409 | Longitude: m.Longitude, 410 | } 411 | case *StickerMessage: 412 | raw.Message = &rawEventMessage{ 413 | Type: MessageTypeSticker, 414 | ID: m.ID, 415 | PackageID: m.PackageID, 416 | StickerID: m.StickerID, 417 | StickerResourceType: m.StickerResourceType, 418 | Keywords: m.Keywords, 419 | Text: m.Text, 420 | } 421 | } 422 | return json.Marshal(&raw) 423 | } 424 | 425 | // UnmarshalJSON method of Event 426 | func (e *Event) UnmarshalJSON(body []byte) (err error) { 427 | rawEvent := rawEvent{} 428 | if err = json.Unmarshal(body, &rawEvent); err != nil { 429 | return 430 | } 431 | 432 | e.ReplyToken = rawEvent.ReplyToken 433 | e.Type = rawEvent.Type 434 | e.Mode = rawEvent.Mode 435 | e.Timestamp = time.Unix(rawEvent.Timestamp/milliSecPerSec, (rawEvent.Timestamp%milliSecPerSec)*nanoSecPerMilliSec).UTC() 436 | e.Source = rawEvent.Source 437 | e.WebhookEventID = rawEvent.WebhookEventID 438 | e.DeliveryContext = rawEvent.DeliveryContext 439 | 440 | switch rawEvent.Type { 441 | case EventTypeMessage: 442 | switch rawEvent.Message.Type { 443 | case MessageTypeText: 444 | e.Message = &TextMessage{ 445 | ID: rawEvent.Message.ID, 446 | Text: rawEvent.Message.Text, 447 | Emojis: rawEvent.Message.Emojis, 448 | Mention: rawEvent.Message.Mention, 449 | } 450 | case MessageTypeImage: 451 | e.Message = &ImageMessage{ 452 | ID: rawEvent.Message.ID, 453 | ContentProvider: rawEvent.Message.ContentProvider, 454 | ImageSet: rawEvent.Message.ImageSet, 455 | } 456 | case MessageTypeVideo: 457 | e.Message = &VideoMessage{ 458 | ID: rawEvent.Message.ID, 459 | Duration: rawEvent.Message.Duration, 460 | ContentProvider: rawEvent.Message.ContentProvider, 461 | } 462 | case MessageTypeAudio: 463 | e.Message = &AudioMessage{ 464 | ID: rawEvent.Message.ID, 465 | Duration: rawEvent.Message.Duration, 466 | ContentProvider: rawEvent.Message.ContentProvider, 467 | } 468 | case MessageTypeFile: 469 | e.Message = &FileMessage{ 470 | ID: rawEvent.Message.ID, 471 | FileName: rawEvent.Message.FileName, 472 | FileSize: rawEvent.Message.FileSize, 473 | } 474 | case MessageTypeLocation: 475 | e.Message = &LocationMessage{ 476 | ID: rawEvent.Message.ID, 477 | Title: rawEvent.Message.Title, 478 | Address: rawEvent.Message.Address, 479 | Latitude: rawEvent.Message.Latitude, 480 | Longitude: rawEvent.Message.Longitude, 481 | } 482 | case MessageTypeSticker: 483 | e.Message = &StickerMessage{ 484 | ID: rawEvent.Message.ID, 485 | PackageID: rawEvent.Message.PackageID, 486 | StickerID: rawEvent.Message.StickerID, 487 | StickerResourceType: rawEvent.Message.StickerResourceType, 488 | Keywords: rawEvent.Message.Keywords, 489 | Text: rawEvent.Message.Text, 490 | } 491 | } 492 | case EventTypePostback: 493 | e.Postback = rawEvent.Postback 494 | case EventTypeBeacon: 495 | var deviceMessage []byte 496 | deviceMessage, err = hex.DecodeString(rawEvent.Beacon.DM) 497 | if err != nil { 498 | return 499 | } 500 | e.Beacon = &Beacon{ 501 | Hwid: rawEvent.Beacon.Hwid, 502 | Type: rawEvent.Beacon.Type, 503 | DeviceMessage: deviceMessage, 504 | } 505 | case EventTypeAccountLink: 506 | e.AccountLink = &AccountLink{ 507 | Result: rawEvent.AccountLink.Result, 508 | Nonce: rawEvent.AccountLink.Nonce, 509 | } 510 | case EventTypeMemberJoined: 511 | e.Members = rawEvent.Joined.Members 512 | case EventTypeMemberLeft: 513 | e.Members = rawEvent.Left.Members 514 | case EventTypeThings: 515 | e.Things = &Things{ 516 | Type: rawEvent.Things.Type, 517 | DeviceID: rawEvent.Things.DeviceID, 518 | } 519 | if rawEvent.Things.Result != nil { 520 | rawResult := rawEvent.Things.Result 521 | e.Things.Result = &ThingsResult{ 522 | ScenarioID: rawResult.ScenarioID, 523 | Revision: rawResult.Revision, 524 | StartTime: rawResult.StartTime, 525 | EndTime: rawResult.EndTime, 526 | ResultCode: rawResult.ResultCode, 527 | ActionResults: make([]*ThingsActionResult, len(rawResult.ActionResults)), 528 | BLENotificationPayload: []byte(rawResult.BLENotificationPayload), 529 | ErrorReason: rawResult.ErrorReason, 530 | } 531 | for i := range rawResult.ActionResults { 532 | e.Things.Result.ActionResults[i] = &ThingsActionResult{ 533 | Type: rawResult.ActionResults[i].Type, 534 | Data: []byte(rawResult.ActionResults[i].Data), 535 | } 536 | } 537 | } 538 | case EventTypeUnsend: 539 | e.Unsend = rawEvent.Unsend 540 | case EventTypeVideoPlayComplete: 541 | e.VideoPlayComplete = rawEvent.VideoPlayComplete 542 | } 543 | return 544 | } 545 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/flex_unmarshal.go: -------------------------------------------------------------------------------- 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 | "errors" 20 | ) 21 | 22 | // UnmarshalFlexMessageJSON function 23 | func UnmarshalFlexMessageJSON(data []byte) (FlexContainer, error) { 24 | raw := rawFlexContainer{} 25 | if err := json.Unmarshal(data, &raw); err != nil { 26 | return nil, err 27 | } 28 | return raw.Container, nil 29 | } 30 | 31 | type rawFlexContainer struct { 32 | Type FlexContainerType `json:"type"` 33 | Container FlexContainer `json:"-"` 34 | } 35 | 36 | func (c *rawFlexContainer) UnmarshalJSON(data []byte) error { 37 | type alias rawFlexContainer 38 | raw := alias{} 39 | if err := json.Unmarshal(data, &raw); err != nil { 40 | return err 41 | } 42 | var container FlexContainer 43 | switch raw.Type { 44 | case FlexContainerTypeBubble: 45 | container = &BubbleContainer{} 46 | case FlexContainerTypeCarousel: 47 | container = &CarouselContainer{} 48 | default: 49 | return errors.New("invalid container type") 50 | } 51 | if err := json.Unmarshal(data, container); err != nil { 52 | return err 53 | } 54 | c.Type = raw.Type 55 | c.Container = container 56 | return nil 57 | } 58 | 59 | type rawFlexComponent struct { 60 | Type FlexComponentType `json:"type"` 61 | Component FlexComponent `json:"-"` 62 | } 63 | 64 | func (c *rawFlexComponent) UnmarshalJSON(data []byte) error { 65 | type alias rawFlexComponent 66 | raw := alias{} 67 | if err := json.Unmarshal(data, &raw); err != nil { 68 | return err 69 | } 70 | var component FlexComponent 71 | switch raw.Type { 72 | case FlexComponentTypeBox: 73 | component = &BoxComponent{} 74 | case FlexComponentTypeButton: 75 | component = &ButtonComponent{} 76 | case FlexComponentTypeFiller: 77 | component = &FillerComponent{} 78 | case FlexComponentTypeIcon: 79 | component = &IconComponent{} 80 | case FlexComponentTypeImage: 81 | component = &ImageComponent{} 82 | case FlexComponentTypeSeparator: 83 | component = &SeparatorComponent{} 84 | case FlexComponentTypeSpacer: 85 | component = &SpacerComponent{} 86 | case FlexComponentTypeText: 87 | component = &TextComponent{} 88 | case FlexComponentTypeVideo: 89 | component = &VideoComponent{} 90 | default: 91 | return errors.New("invalid flex component type") 92 | } 93 | if err := json.Unmarshal(data, component); err != nil { 94 | return err 95 | } 96 | c.Type = raw.Type 97 | c.Component = component 98 | return nil 99 | } 100 | 101 | type rawAction struct { 102 | Type ActionType `json:"type"` 103 | Action TemplateAction `json:"-"` 104 | } 105 | 106 | func (c *rawAction) UnmarshalJSON(data []byte) error { 107 | type alias rawAction 108 | raw := alias{} 109 | if err := json.Unmarshal(data, &raw); err != nil { 110 | return err 111 | } 112 | var action TemplateAction 113 | switch raw.Type { 114 | case ActionTypeURI: 115 | action = &URIAction{} 116 | case ActionTypeMessage: 117 | action = &MessageAction{} 118 | case ActionTypePostback: 119 | action = &PostbackAction{} 120 | case ActionTypeDatetimePicker: 121 | action = &DatetimePickerAction{} 122 | default: 123 | return errors.New("invalid action type") 124 | } 125 | if err := json.Unmarshal(data, action); err != nil { 126 | return err 127 | } 128 | c.Type = raw.Type 129 | c.Action = action 130 | return nil 131 | } 132 | 133 | // UnmarshalJSON method for BoxComponent 134 | func (c *BoxComponent) UnmarshalJSON(data []byte) error { 135 | type alias BoxComponent 136 | raw := struct { 137 | Contents []rawFlexComponent `json:"contents"` 138 | Action rawAction `json:"action"` 139 | *alias 140 | }{ 141 | alias: (*alias)(c), 142 | } 143 | if err := json.Unmarshal(data, &raw); err != nil { 144 | return err 145 | } 146 | components := make([]FlexComponent, len(raw.Contents)) 147 | for i, content := range raw.Contents { 148 | components[i] = content.Component 149 | } 150 | c.Contents = components 151 | c.Action = raw.Action.Action 152 | return nil 153 | } 154 | 155 | // UnmarshalJSON method for ButtonComponent 156 | func (c *ButtonComponent) UnmarshalJSON(data []byte) error { 157 | type alias ButtonComponent 158 | raw := struct { 159 | Action rawAction `json:"action"` 160 | *alias 161 | }{ 162 | alias: (*alias)(c), 163 | } 164 | if err := json.Unmarshal(data, &raw); err != nil { 165 | return err 166 | } 167 | c.Action = raw.Action.Action 168 | return nil 169 | } 170 | 171 | // UnmarshalJSON method for ImageComponent 172 | func (c *ImageComponent) UnmarshalJSON(data []byte) error { 173 | type alias ImageComponent 174 | raw := struct { 175 | Action rawAction `json:"action"` 176 | *alias 177 | }{ 178 | alias: (*alias)(c), 179 | } 180 | if err := json.Unmarshal(data, &raw); err != nil { 181 | return err 182 | } 183 | c.Action = raw.Action.Action 184 | return nil 185 | } 186 | 187 | // UnmarshalJSON method for TextComponent 188 | func (c *TextComponent) UnmarshalJSON(data []byte) error { 189 | type alias TextComponent 190 | raw := struct { 191 | Action rawAction `json:"action"` 192 | *alias 193 | }{ 194 | alias: (*alias)(c), 195 | } 196 | if err := json.Unmarshal(data, &raw); err != nil { 197 | return err 198 | } 199 | c.Action = raw.Action.Action 200 | return nil 201 | } 202 | 203 | // UnmarshalJSON method for VideoComponent 204 | func (c *VideoComponent) UnmarshalJSON(data []byte) error { 205 | type alias VideoComponent 206 | raw := struct { 207 | AltContent rawFlexComponent `json:"altContent"` 208 | *alias 209 | }{ 210 | alias: (*alias)(c), 211 | } 212 | if err := json.Unmarshal(data, &raw); err != nil { 213 | return err 214 | } 215 | c.AltContent = raw.AltContent.Component 216 | return nil 217 | } 218 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/get_bot_info.go: -------------------------------------------------------------------------------- 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 | "context" 19 | ) 20 | 21 | // ChatMode type 22 | type ChatMode string 23 | 24 | // ChatMode constants 25 | const ( 26 | ChatModeChat ChatMode = "chat" 27 | ChatModeBot ChatMode = "bot" 28 | ) 29 | 30 | // MarkAsReadMode type 31 | type MarkAsReadMode string 32 | 33 | // MarkAsReadMode constants 34 | const ( 35 | MarkAsReadModeManual MarkAsReadMode = "manual" 36 | MarkAsReadModeAuto MarkAsReadMode = "auto" 37 | ) 38 | 39 | // GetBotInfo method 40 | func (client *Client) GetBotInfo() *GetBotInfoCall { 41 | return &GetBotInfoCall{ 42 | c: client, 43 | endpoint: APIEndpointGetBotInfo, 44 | } 45 | } 46 | 47 | // WithContext method 48 | func (call *GetBotInfoCall) WithContext(ctx context.Context) *GetBotInfoCall { 49 | call.ctx = ctx 50 | return call 51 | } 52 | 53 | // Do method 54 | func (call *GetBotInfoCall) Do() (*BotInfoResponse, error) { 55 | res, err := call.c.get(call.ctx, call.c.endpointBase, call.endpoint, nil) 56 | if err != nil { 57 | return nil, err 58 | } 59 | defer closeResponse(res) 60 | return decodeToBotInfoResponse(res) 61 | } 62 | 63 | // GetBotInfoCall type 64 | type GetBotInfoCall struct { 65 | c *Client 66 | ctx context.Context 67 | endpoint string 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/get_content.go: -------------------------------------------------------------------------------- 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 | "context" 19 | "fmt" 20 | ) 21 | 22 | // GetMessageContent method 23 | func (client *Client) GetMessageContent(messageID string) *GetMessageContentCall { 24 | return &GetMessageContentCall{ 25 | c: client, 26 | messageID: messageID, 27 | } 28 | } 29 | 30 | // GetMessageContentCall type 31 | type GetMessageContentCall struct { 32 | c *Client 33 | ctx context.Context 34 | 35 | messageID string 36 | } 37 | 38 | // WithContext method 39 | func (call *GetMessageContentCall) WithContext(ctx context.Context) *GetMessageContentCall { 40 | call.ctx = ctx 41 | return call 42 | } 43 | 44 | // Do method 45 | func (call *GetMessageContentCall) Do() (*MessageContentResponse, error) { 46 | endpoint := fmt.Sprintf(APIEndpointGetMessageContent, call.messageID) 47 | res, err := call.c.get(call.ctx, call.c.endpointBaseData, endpoint, nil) 48 | if err != nil { 49 | return nil, err 50 | } 51 | defer closeResponse(res) 52 | return decodeToMessageContentResponse(res) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/get_count.go: -------------------------------------------------------------------------------- 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 ( 18 | "context" 19 | "fmt" 20 | ) 21 | 22 | // GetGroupMemberCount method 23 | func (client *Client) GetGroupMemberCount(groupID string) *GetGroupMemberCountCall { 24 | return &GetGroupMemberCountCall{ 25 | c: client, 26 | groupID: groupID, 27 | } 28 | } 29 | 30 | // GetGroupMemberCountCall type 31 | type GetGroupMemberCountCall struct { 32 | c *Client 33 | ctx context.Context 34 | 35 | groupID string 36 | } 37 | 38 | // WithContext method 39 | func (call *GetGroupMemberCountCall) WithContext(ctx context.Context) *GetGroupMemberCountCall { 40 | call.ctx = ctx 41 | return call 42 | } 43 | 44 | // Do method 45 | func (call *GetGroupMemberCountCall) Do() (*MemberCountResponse, error) { 46 | endpoint := fmt.Sprintf(APIEndpointGetGroupMemberCount, call.groupID) 47 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil) 48 | if err != nil { 49 | return nil, err 50 | } 51 | defer closeResponse(res) 52 | return decodeToMemberCountResponse(res) 53 | } 54 | 55 | // GetRoomMemberCount method 56 | func (client *Client) GetRoomMemberCount(roomID string) *GetRoomMemberCountCall { 57 | return &GetRoomMemberCountCall{ 58 | c: client, 59 | roomID: roomID, 60 | } 61 | } 62 | 63 | // GetRoomMemberCountCall type 64 | type GetRoomMemberCountCall struct { 65 | c *Client 66 | ctx context.Context 67 | 68 | roomID string 69 | } 70 | 71 | // WithContext method 72 | func (call *GetRoomMemberCountCall) WithContext(ctx context.Context) *GetRoomMemberCountCall { 73 | call.ctx = ctx 74 | return call 75 | } 76 | 77 | // Do method 78 | func (call *GetRoomMemberCountCall) Do() (*MemberCountResponse, error) { 79 | endpoint := fmt.Sprintf(APIEndpointGetRoomMemberCount, call.roomID) 80 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil) 81 | if err != nil { 82 | return nil, err 83 | } 84 | defer closeResponse(res) 85 | return decodeToMemberCountResponse(res) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/get_follower_ids.go: -------------------------------------------------------------------------------- 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 | "context" 19 | "net/url" 20 | ) 21 | 22 | // GetFollowerIDs method 23 | func (client *Client) GetFollowerIDs(continuationToken string) *GetFollowerIDsCall { 24 | return &GetFollowerIDsCall{ 25 | c: client, 26 | continuationToken: continuationToken, 27 | } 28 | } 29 | 30 | // GetFollowerIDsCall type 31 | type GetFollowerIDsCall struct { 32 | c *Client 33 | ctx context.Context 34 | 35 | continuationToken string 36 | } 37 | 38 | // WithContext method 39 | func (call *GetFollowerIDsCall) WithContext(ctx context.Context) *GetFollowerIDsCall { 40 | call.ctx = ctx 41 | return call 42 | } 43 | 44 | // Do method 45 | func (call *GetFollowerIDsCall) Do() (*UserIDsResponse, error) { 46 | var q url.Values 47 | if call.continuationToken != "" { 48 | q = url.Values{"start": []string{call.continuationToken}} 49 | } 50 | res, err := call.c.get(call.ctx, call.c.endpointBase, APIEndpointGetFollowerIDs, q) 51 | if err != nil { 52 | return nil, err 53 | } 54 | defer closeResponse(res) 55 | return decodeToUserIDsResponse(res) 56 | } 57 | 58 | // NewScanner returns Group IDs scanner. 59 | func (call *GetFollowerIDsCall) NewScanner() *UserIDsScanner { 60 | var ctx context.Context 61 | if call.ctx != nil { 62 | ctx = call.ctx 63 | } else { 64 | ctx = context.Background() 65 | } 66 | 67 | c2 := &GetFollowerIDsCall{} 68 | *c2 = *call 69 | c2.ctx = ctx 70 | 71 | return &UserIDsScanner{ 72 | caller: c2, 73 | ctx: ctx, 74 | } 75 | } 76 | 77 | func (call *GetFollowerIDsCall) setContinuationToken(token string) { 78 | call.continuationToken = token 79 | } 80 | 81 | type userIDsCaller interface { 82 | Do() (*UserIDsResponse, error) 83 | setContinuationToken(string) 84 | } 85 | 86 | // UserIDsScanner type 87 | type UserIDsScanner struct { 88 | caller userIDsCaller 89 | ctx context.Context 90 | start int 91 | ids []string 92 | next string 93 | called bool 94 | done bool 95 | err error 96 | } 97 | 98 | // Scan method 99 | func (s *UserIDsScanner) Scan() bool { 100 | if s.done { 101 | return false 102 | } 103 | 104 | select { 105 | case <-s.ctx.Done(): 106 | s.err = s.ctx.Err() 107 | s.done = true 108 | return false 109 | default: 110 | } 111 | 112 | s.start++ 113 | if len(s.ids) > 0 && len(s.ids) > s.start { 114 | return true 115 | } 116 | 117 | if s.next == "" && s.called { 118 | s.done = true 119 | return false 120 | } 121 | 122 | s.start = 0 123 | res, err := s.caller.Do() 124 | if err != nil { 125 | s.err = err 126 | s.done = true 127 | return false 128 | } 129 | 130 | s.called = true 131 | s.ids = res.UserIDs 132 | s.next = res.Next 133 | s.caller.setContinuationToken(s.next) 134 | 135 | return true 136 | } 137 | 138 | // ID returns member id. 139 | func (s *UserIDsScanner) ID() string { 140 | if len(s.ids) == 0 { 141 | return "" 142 | } 143 | return s.ids[s.start : s.start+1][0] 144 | } 145 | 146 | // Err returns scan error. 147 | func (s *UserIDsScanner) Err() error { 148 | return s.err 149 | } 150 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/get_ids.go: -------------------------------------------------------------------------------- 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 | "context" 19 | "fmt" 20 | "net/url" 21 | ) 22 | 23 | // GetGroupMemberIDs method 24 | func (client *Client) GetGroupMemberIDs(groupID, continuationToken string) *GetGroupMemberIDsCall { 25 | return &GetGroupMemberIDsCall{ 26 | c: client, 27 | groupID: groupID, 28 | continuationToken: continuationToken, 29 | } 30 | } 31 | 32 | // GetGroupMemberIDsCall type 33 | type GetGroupMemberIDsCall struct { 34 | c *Client 35 | ctx context.Context 36 | 37 | groupID string 38 | continuationToken string 39 | } 40 | 41 | // WithContext method 42 | func (call *GetGroupMemberIDsCall) WithContext(ctx context.Context) *GetGroupMemberIDsCall { 43 | call.ctx = ctx 44 | return call 45 | } 46 | 47 | // Do method 48 | func (call *GetGroupMemberIDsCall) Do() (*MemberIDsResponse, error) { 49 | endpoint := fmt.Sprintf(APIEndpointGetGroupMemberIDs, call.groupID) 50 | var q url.Values 51 | if call.continuationToken != "" { 52 | q = url.Values{"start": []string{call.continuationToken}} 53 | } 54 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q) 55 | if err != nil { 56 | return nil, err 57 | } 58 | defer closeResponse(res) 59 | return decodeToMemberIDsResponse(res) 60 | } 61 | 62 | // GetRoomMemberIDs method 63 | func (client *Client) GetRoomMemberIDs(roomID, continuationToken string) *GetRoomMemberIDsCall { 64 | return &GetRoomMemberIDsCall{ 65 | c: client, 66 | roomID: roomID, 67 | continuationToken: continuationToken, 68 | } 69 | } 70 | 71 | // GetRoomMemberIDsCall type 72 | type GetRoomMemberIDsCall struct { 73 | c *Client 74 | ctx context.Context 75 | 76 | roomID string 77 | continuationToken string 78 | } 79 | 80 | // WithContext method 81 | func (call *GetRoomMemberIDsCall) WithContext(ctx context.Context) *GetRoomMemberIDsCall { 82 | call.ctx = ctx 83 | return call 84 | } 85 | 86 | // Do method 87 | func (call *GetRoomMemberIDsCall) Do() (*MemberIDsResponse, error) { 88 | endpoint := fmt.Sprintf(APIEndpointGetRoomMemberIDs, call.roomID) 89 | var q url.Values 90 | if call.continuationToken != "" { 91 | q = url.Values{"start": []string{call.continuationToken}} 92 | } 93 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q) 94 | if err != nil { 95 | return nil, err 96 | } 97 | defer closeResponse(res) 98 | return decodeToMemberIDsResponse(res) 99 | } 100 | 101 | // NewScanner returns Group IDs scanner. 102 | func (call *GetGroupMemberIDsCall) NewScanner() *IDsScanner { 103 | var ctx context.Context 104 | if call.ctx != nil { 105 | ctx = call.ctx 106 | } else { 107 | ctx = context.Background() 108 | } 109 | 110 | c2 := &GetGroupMemberIDsCall{} 111 | *c2 = *call 112 | c2.ctx = ctx 113 | 114 | return &IDsScanner{ 115 | caller: c2, 116 | ctx: ctx, 117 | } 118 | } 119 | 120 | func (call *GetGroupMemberIDsCall) setContinuationToken(token string) { 121 | call.continuationToken = token 122 | } 123 | 124 | // NewScanner returns Room IDs scanner. 125 | func (call *GetRoomMemberIDsCall) NewScanner() *IDsScanner { 126 | var ctx context.Context 127 | if call.ctx != nil { 128 | ctx = call.ctx 129 | } else { 130 | ctx = context.Background() 131 | } 132 | 133 | c2 := &GetRoomMemberIDsCall{} 134 | *c2 = *call 135 | c2.ctx = ctx 136 | 137 | return &IDsScanner{ 138 | caller: c2, 139 | ctx: ctx, 140 | } 141 | } 142 | 143 | func (call *GetRoomMemberIDsCall) setContinuationToken(token string) { 144 | call.continuationToken = token 145 | } 146 | 147 | type memberIDsCaller interface { 148 | Do() (*MemberIDsResponse, error) 149 | setContinuationToken(string) 150 | } 151 | 152 | // IDsScanner type 153 | type IDsScanner struct { 154 | caller memberIDsCaller 155 | ctx context.Context 156 | start int 157 | ids []string 158 | next string 159 | called bool 160 | done bool 161 | err error 162 | } 163 | 164 | // Scan method 165 | func (s *IDsScanner) Scan() bool { 166 | if s.done { 167 | return false 168 | } 169 | 170 | select { 171 | case <-s.ctx.Done(): 172 | s.err = s.ctx.Err() 173 | s.done = true 174 | return false 175 | default: 176 | } 177 | 178 | s.start++ 179 | if len(s.ids) > 0 && len(s.ids) > s.start { 180 | return true 181 | } 182 | 183 | if s.next == "" && s.called { 184 | s.done = true 185 | return false 186 | } 187 | 188 | s.start = 0 189 | res, err := s.caller.Do() 190 | if err != nil { 191 | s.err = err 192 | s.done = true 193 | return false 194 | } 195 | 196 | s.called = true 197 | s.ids = res.MemberIDs 198 | s.next = res.Next 199 | s.caller.setContinuationToken(s.next) 200 | 201 | return true 202 | } 203 | 204 | // ID returns member id. 205 | func (s *IDsScanner) ID() string { 206 | if len(s.ids) == 0 { 207 | return "" 208 | } 209 | return s.ids[s.start : s.start+1][0] 210 | } 211 | 212 | // Err returns scan error. 213 | func (s *IDsScanner) Err() error { 214 | return s.err 215 | } 216 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/get_profile.go: -------------------------------------------------------------------------------- 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 | "context" 19 | "fmt" 20 | ) 21 | 22 | // GetProfile method 23 | func (client *Client) GetProfile(userID string) *GetProfileCall { 24 | return &GetProfileCall{ 25 | c: client, 26 | userID: userID, 27 | } 28 | } 29 | 30 | // GetProfileCall type 31 | type GetProfileCall struct { 32 | c *Client 33 | ctx context.Context 34 | 35 | userID string 36 | } 37 | 38 | // WithContext method 39 | func (call *GetProfileCall) WithContext(ctx context.Context) *GetProfileCall { 40 | call.ctx = ctx 41 | return call 42 | } 43 | 44 | // Do method 45 | func (call *GetProfileCall) Do() (*UserProfileResponse, error) { 46 | endpoint := fmt.Sprintf(APIEndpointGetProfile, call.userID) 47 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil) 48 | if err != nil { 49 | return nil, err 50 | } 51 | defer closeResponse(res) 52 | return decodeToUserProfileResponse(res) 53 | } 54 | 55 | // GetGroupMemberProfile method 56 | func (client *Client) GetGroupMemberProfile(groupID, userID string) *GetGroupMemberProfileCall { 57 | return &GetGroupMemberProfileCall{ 58 | c: client, 59 | groupID: groupID, 60 | userID: userID, 61 | } 62 | } 63 | 64 | // GetGroupMemberProfileCall type 65 | type GetGroupMemberProfileCall struct { 66 | c *Client 67 | ctx context.Context 68 | 69 | groupID string 70 | userID string 71 | } 72 | 73 | // WithContext method 74 | func (call *GetGroupMemberProfileCall) WithContext(ctx context.Context) *GetGroupMemberProfileCall { 75 | call.ctx = ctx 76 | return call 77 | } 78 | 79 | // Do method 80 | func (call *GetGroupMemberProfileCall) Do() (*UserProfileResponse, error) { 81 | endpoint := fmt.Sprintf(APIEndpointGetGroupMemberProfile, call.groupID, call.userID) 82 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil) 83 | if err != nil { 84 | return nil, err 85 | } 86 | defer closeResponse(res) 87 | return decodeToUserProfileResponse(res) 88 | } 89 | 90 | // GetRoomMemberProfile method 91 | func (client *Client) GetRoomMemberProfile(roomID, userID string) *GetRoomMemberProfileCall { 92 | return &GetRoomMemberProfileCall{ 93 | c: client, 94 | roomID: roomID, 95 | userID: userID, 96 | } 97 | } 98 | 99 | // GetRoomMemberProfileCall type 100 | type GetRoomMemberProfileCall struct { 101 | c *Client 102 | ctx context.Context 103 | 104 | roomID string 105 | userID string 106 | } 107 | 108 | // WithContext method 109 | func (call *GetRoomMemberProfileCall) WithContext(ctx context.Context) *GetRoomMemberProfileCall { 110 | call.ctx = ctx 111 | return call 112 | } 113 | 114 | // Do method 115 | func (call *GetRoomMemberProfileCall) Do() (*UserProfileResponse, error) { 116 | endpoint := fmt.Sprintf(APIEndpointGetRoomMemberProfile, call.roomID, call.userID) 117 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil) 118 | if err != nil { 119 | return nil, err 120 | } 121 | defer closeResponse(res) 122 | return decodeToUserProfileResponse(res) 123 | } 124 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/get_quota.go: -------------------------------------------------------------------------------- 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 | "context" 19 | ) 20 | 21 | // GetMessageQuota method 22 | func (client *Client) GetMessageQuota() *GetMessageQuotaCall { 23 | return &GetMessageQuotaCall{ 24 | c: client, 25 | endpoint: APIEndpointGetMessageQuota, 26 | } 27 | } 28 | 29 | // GetMessageQuotaConsumption method 30 | func (client *Client) GetMessageQuotaConsumption() *GetMessageQuotaCall { 31 | return &GetMessageQuotaCall{ 32 | c: client, 33 | endpoint: APIEndpointGetMessageQuotaConsumption, 34 | } 35 | } 36 | 37 | // GetMessageQuotaCall type 38 | type GetMessageQuotaCall struct { 39 | c *Client 40 | ctx context.Context 41 | endpoint string 42 | } 43 | 44 | // WithContext method 45 | func (call *GetMessageQuotaCall) WithContext(ctx context.Context) *GetMessageQuotaCall { 46 | call.ctx = ctx 47 | return call 48 | } 49 | 50 | // Do method 51 | func (call *GetMessageQuotaCall) Do() (*MessageQuotaResponse, error) { 52 | res, err := call.c.get(call.ctx, call.c.endpointBase, call.endpoint, nil) 53 | if err != nil { 54 | return nil, err 55 | } 56 | defer closeResponse(res) 57 | return decodeToMessageQuotaResponse(res) 58 | } 59 | 60 | // GetMessageConsumption method 61 | func (client *Client) GetMessageConsumption() *GetMessageConsumptionCall { 62 | return &GetMessageConsumptionCall{ 63 | c: client, 64 | } 65 | } 66 | 67 | // GetMessageConsumptionCall type 68 | type GetMessageConsumptionCall struct { 69 | c *Client 70 | ctx context.Context 71 | } 72 | 73 | // WithContext method 74 | func (call *GetMessageConsumptionCall) WithContext(ctx context.Context) *GetMessageConsumptionCall { 75 | call.ctx = ctx 76 | return call 77 | } 78 | 79 | // Do method 80 | func (call *GetMessageConsumptionCall) Do() (*MessageConsumptionResponse, error) { 81 | res, err := call.c.get(call.ctx, call.c.endpointBase, APIEndpointGetMessageConsumption, nil) 82 | if err != nil { 83 | return nil, err 84 | } 85 | defer closeResponse(res) 86 | return decodeToMessageConsumptionResponse(res) 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/get_summary.go: -------------------------------------------------------------------------------- 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 ( 18 | "context" 19 | "fmt" 20 | ) 21 | 22 | // GetGroupSummary method 23 | func (client *Client) GetGroupSummary(groupID string) *GetGroupSummaryCall { 24 | return &GetGroupSummaryCall{ 25 | c: client, 26 | groupID: groupID, 27 | } 28 | } 29 | 30 | // GetGroupSummaryCall type 31 | type GetGroupSummaryCall struct { 32 | c *Client 33 | ctx context.Context 34 | 35 | groupID string 36 | } 37 | 38 | // WithContext method 39 | func (call *GetGroupSummaryCall) WithContext(ctx context.Context) *GetGroupSummaryCall { 40 | call.ctx = ctx 41 | return call 42 | } 43 | 44 | // Do method 45 | func (call *GetGroupSummaryCall) Do() (*GroupSummaryResponse, error) { 46 | endpoint := fmt.Sprintf(APIEndpointGetGroupSummary, call.groupID) 47 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, nil) 48 | if err != nil { 49 | return nil, err 50 | } 51 | defer closeResponse(res) 52 | return decodeToGroupSummaryResponse(res) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/imagemap.go: -------------------------------------------------------------------------------- 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 | "encoding/json" 19 | ) 20 | 21 | // ImagemapActionType type 22 | type ImagemapActionType string 23 | 24 | // ImagemapActionType constants 25 | const ( 26 | ImagemapActionTypeURI ImagemapActionType = "uri" 27 | ImagemapActionTypeMessage ImagemapActionType = "message" 28 | ) 29 | 30 | // ImagemapBaseSize type 31 | type ImagemapBaseSize struct { 32 | Width int `json:"width"` 33 | Height int `json:"height"` 34 | } 35 | 36 | // ImagemapArea type 37 | type ImagemapArea struct { 38 | X int `json:"x"` 39 | Y int `json:"y"` 40 | Width int `json:"width"` 41 | Height int `json:"height"` 42 | } 43 | 44 | // ImagemapVideo type 45 | type ImagemapVideo struct { 46 | OriginalContentURL string `json:"originalContentUrl"` 47 | PreviewImageURL string `json:"previewImageUrl"` 48 | Area ImagemapArea `json:"area"` 49 | ExternalLink *ImagemapVideoExternalLink `json:"externalLink,omitempty"` 50 | } 51 | 52 | // ImagemapVideoExternalLink type 53 | type ImagemapVideoExternalLink struct { 54 | LinkURI string `json:"linkUri"` 55 | Label string `json:"label"` 56 | } 57 | 58 | // ImagemapAction type 59 | type ImagemapAction interface { 60 | json.Marshaler 61 | ImagemapAction() 62 | } 63 | 64 | // URIImagemapAction type 65 | type URIImagemapAction struct { 66 | Label string 67 | LinkURL string 68 | Area ImagemapArea 69 | } 70 | 71 | // MarshalJSON method of URIImagemapAction 72 | func (a *URIImagemapAction) MarshalJSON() ([]byte, error) { 73 | return json.Marshal(&struct { 74 | Type ImagemapActionType `json:"type"` 75 | Label string `json:"label,omitempty"` 76 | LinkURL string `json:"linkUri"` 77 | Area ImagemapArea `json:"area"` 78 | }{ 79 | Type: ImagemapActionTypeURI, 80 | Label: a.Label, 81 | LinkURL: a.LinkURL, 82 | Area: a.Area, 83 | }) 84 | } 85 | 86 | // MessageImagemapAction type 87 | type MessageImagemapAction struct { 88 | Label string 89 | Text string 90 | Area ImagemapArea 91 | } 92 | 93 | // MarshalJSON method of MessageImagemapAction 94 | func (a *MessageImagemapAction) MarshalJSON() ([]byte, error) { 95 | return json.Marshal(&struct { 96 | Type ImagemapActionType `json:"type"` 97 | Label string `json:"label,omitempty"` 98 | Text string `json:"text"` 99 | Area ImagemapArea `json:"area"` 100 | }{ 101 | Type: ImagemapActionTypeMessage, 102 | Label: a.Label, 103 | Text: a.Text, 104 | Area: a.Area, 105 | }) 106 | } 107 | 108 | // ImagemapAction implements ImagemapAction interface 109 | func (a *URIImagemapAction) ImagemapAction() {} 110 | 111 | // ImagemapAction implements ImagemapAction interface 112 | func (a *MessageImagemapAction) ImagemapAction() {} 113 | 114 | // NewURIImagemapAction function 115 | func NewURIImagemapAction(label, linkURL string, area ImagemapArea) *URIImagemapAction { 116 | return &URIImagemapAction{ 117 | Label: label, 118 | LinkURL: linkURL, 119 | Area: area, 120 | } 121 | } 122 | 123 | // NewMessageImagemapAction function 124 | func NewMessageImagemapAction(label, text string, area ImagemapArea) *MessageImagemapAction { 125 | return &MessageImagemapAction{ 126 | Label: label, 127 | Text: text, 128 | Area: area, 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/imageset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | // ImageSet type 18 | type ImageSet struct { 19 | ID string `json:"id"` 20 | Index int `json:"index"` 21 | Total int `json:"total"` 22 | } 23 | 24 | // NewImageSet function 25 | func NewImageSet(ID string, index, total int) *ImageSet { 26 | return &ImageSet{ 27 | ID: ID, 28 | Index: index, 29 | Total: total, 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/insight.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 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 | "context" 19 | "fmt" 20 | "net/url" 21 | ) 22 | 23 | // InsightType type 24 | type InsightType string 25 | 26 | // InsightType constants 27 | const ( 28 | InsightTypeMessageDelivery InsightType = "message/delivery" 29 | InsightTypeUserInteractionStats InsightType = "message/event" 30 | InsightTypeFollowers InsightType = "followers" 31 | InsightTypeDemographic InsightType = "demographic" 32 | ) 33 | 34 | // GetNumberMessagesDeliveryCall type 35 | type GetNumberMessagesDeliveryCall struct { 36 | c *Client 37 | ctx context.Context 38 | 39 | date string 40 | insightType InsightType 41 | } 42 | 43 | // GetNumberMessagesDelivery method 44 | func (client *Client) GetNumberMessagesDelivery(date string) *GetNumberMessagesDeliveryCall { 45 | return &GetNumberMessagesDeliveryCall{ 46 | c: client, 47 | date: date, 48 | insightType: InsightTypeMessageDelivery, 49 | } 50 | } 51 | 52 | // WithContext method 53 | func (call *GetNumberMessagesDeliveryCall) WithContext(ctx context.Context) *GetNumberMessagesDeliveryCall { 54 | call.ctx = ctx 55 | return call 56 | } 57 | 58 | // Do method 59 | func (call *GetNumberMessagesDeliveryCall) Do() (*MessagesNumberDeliveryResponse, error) { 60 | endpoint := fmt.Sprintf(APIEndpointInsight, call.insightType) 61 | q := url.Values{} 62 | if call.date != "" { 63 | q.Add("date", call.date) 64 | } 65 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q) 66 | if err != nil { 67 | return nil, err 68 | } 69 | defer closeResponse(res) 70 | return decodeToMessagesNumberDeliveryResponse(res) 71 | } 72 | 73 | // GetNumberFollowersCall type 74 | type GetNumberFollowersCall struct { 75 | c *Client 76 | ctx context.Context 77 | 78 | date string 79 | insightType InsightType 80 | } 81 | 82 | // GetNumberFollowers method 83 | func (client *Client) GetNumberFollowers(date string) *GetNumberFollowersCall { 84 | return &GetNumberFollowersCall{ 85 | c: client, 86 | date: date, 87 | insightType: InsightTypeFollowers, 88 | } 89 | } 90 | 91 | // WithContext method 92 | func (call *GetNumberFollowersCall) WithContext(ctx context.Context) *GetNumberFollowersCall { 93 | call.ctx = ctx 94 | return call 95 | } 96 | 97 | // Do method 98 | func (call *GetNumberFollowersCall) Do() (*MessagesNumberFollowersResponse, error) { 99 | endpoint := fmt.Sprintf(APIEndpointInsight, call.insightType) 100 | q := url.Values{} 101 | if call.date != "" { 102 | q.Add("date", call.date) 103 | } 104 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q) 105 | if err != nil { 106 | return nil, err 107 | } 108 | defer closeResponse(res) 109 | return decodeToMessagesNumberFollowersResponse(res) 110 | } 111 | 112 | // GetFriendDemographicsCall type 113 | type GetFriendDemographicsCall struct { 114 | c *Client 115 | ctx context.Context 116 | 117 | insightType InsightType 118 | } 119 | 120 | // GetFriendDemographics method 121 | func (client *Client) GetFriendDemographics() *GetFriendDemographicsCall { 122 | return &GetFriendDemographicsCall{ 123 | c: client, 124 | insightType: InsightTypeDemographic, 125 | } 126 | } 127 | 128 | // WithContext method 129 | func (call *GetFriendDemographicsCall) WithContext(ctx context.Context) *GetFriendDemographicsCall { 130 | call.ctx = ctx 131 | return call 132 | } 133 | 134 | // Do method 135 | func (call *GetFriendDemographicsCall) Do() (*MessagesFriendDemographicsResponse, error) { 136 | endpoint := fmt.Sprintf(APIEndpointInsight, call.insightType) 137 | var q url.Values 138 | 139 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q) 140 | if err != nil { 141 | return nil, err 142 | } 143 | defer closeResponse(res) 144 | return decodeToMessagesFriendDemographicsResponse(res) 145 | } 146 | 147 | // GetUserInteractionStatsCall type 148 | type GetUserInteractionStatsCall struct { 149 | c *Client 150 | ctx context.Context 151 | 152 | requestID string 153 | insightType InsightType 154 | } 155 | 156 | // GetUserInteractionStats method 157 | func (client *Client) GetUserInteractionStats(requestID string) *GetUserInteractionStatsCall { 158 | return &GetUserInteractionStatsCall{ 159 | c: client, 160 | requestID: requestID, 161 | insightType: InsightTypeUserInteractionStats, 162 | } 163 | } 164 | 165 | // WithContext method 166 | func (call *GetUserInteractionStatsCall) WithContext(ctx context.Context) *GetUserInteractionStatsCall { 167 | call.ctx = ctx 168 | return call 169 | } 170 | 171 | // Do method, returns MessagesUserInteractionStatsResponse 172 | func (call *GetUserInteractionStatsCall) Do() (*MessagesUserInteractionStatsResponse, error) { 173 | endpoint := fmt.Sprintf(APIEndpointInsight, call.insightType) 174 | q := url.Values{} 175 | if call.requestID != "" { 176 | q.Add("requestId", call.requestID) 177 | } 178 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q) 179 | if err != nil { 180 | return nil, err 181 | } 182 | defer closeResponse(res) 183 | return decodeToMessagesUserInteractionStatsResponse(res) 184 | } 185 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/leave.go: -------------------------------------------------------------------------------- 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 | "context" 19 | "fmt" 20 | ) 21 | 22 | // LeaveGroup method 23 | func (client *Client) LeaveGroup(groupID string) *LeaveGroupCall { 24 | return &LeaveGroupCall{ 25 | c: client, 26 | groupID: groupID, 27 | } 28 | } 29 | 30 | // LeaveGroupCall type 31 | type LeaveGroupCall struct { 32 | c *Client 33 | ctx context.Context 34 | 35 | groupID string 36 | } 37 | 38 | // WithContext method 39 | func (call *LeaveGroupCall) WithContext(ctx context.Context) *LeaveGroupCall { 40 | call.ctx = ctx 41 | return call 42 | } 43 | 44 | // Do method 45 | func (call *LeaveGroupCall) Do() (*BasicResponse, error) { 46 | endpoint := fmt.Sprintf(APIEndpointLeaveGroup, call.groupID) 47 | res, err := call.c.post(call.ctx, endpoint, nil) 48 | if err != nil { 49 | return nil, err 50 | } 51 | defer closeResponse(res) 52 | return decodeToBasicResponse(res) 53 | } 54 | 55 | // LeaveRoom method 56 | func (client *Client) LeaveRoom(roomID string) *LeaveRoomCall { 57 | return &LeaveRoomCall{ 58 | c: client, 59 | roomID: roomID, 60 | } 61 | } 62 | 63 | // LeaveRoomCall type 64 | type LeaveRoomCall struct { 65 | c *Client 66 | ctx context.Context 67 | 68 | roomID string 69 | } 70 | 71 | // WithContext method 72 | func (call *LeaveRoomCall) WithContext(ctx context.Context) *LeaveRoomCall { 73 | call.ctx = ctx 74 | return call 75 | } 76 | 77 | // Do method 78 | func (call *LeaveRoomCall) Do() (*BasicResponse, error) { 79 | endpoint := fmt.Sprintf(APIEndpointLeaveRoom, call.roomID) 80 | res, err := call.c.post(call.ctx, endpoint, nil) 81 | if err != nil { 82 | return nil, err 83 | } 84 | defer closeResponse(res) 85 | return decodeToBasicResponse(res) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/liff.go: -------------------------------------------------------------------------------- 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 | "bytes" 19 | "context" 20 | "encoding/json" 21 | "fmt" 22 | "io" 23 | ) 24 | 25 | // LIFFViewType type 26 | type LIFFViewType string 27 | 28 | // LIFFViewType constants 29 | const ( 30 | LIFFViewTypeCompact LIFFViewType = "compact" 31 | LIFFViewTypeTall LIFFViewType = "tall" 32 | LIFFViewTypeFull LIFFViewType = "full" 33 | ) 34 | 35 | // LIFFApp type 36 | type LIFFApp struct { 37 | LIFFID string `json:"liffId"` 38 | View View `json:"view"` 39 | } 40 | 41 | // ViewRequest type 42 | type ViewRequest struct { 43 | View View `json:"view"` 44 | } 45 | 46 | // View type 47 | type View struct { 48 | Type LIFFViewType `json:"type"` 49 | URL string `json:"url"` 50 | } 51 | 52 | // GetLIFF method 53 | func (client *Client) GetLIFF() *GetLIFFAllCall { 54 | return &GetLIFFAllCall{ 55 | c: client, 56 | } 57 | } 58 | 59 | // GetLIFFAllCall type 60 | type GetLIFFAllCall struct { 61 | c *Client 62 | ctx context.Context 63 | } 64 | 65 | // WithContext method 66 | func (call *GetLIFFAllCall) WithContext(ctx context.Context) *GetLIFFAllCall { 67 | call.ctx = ctx 68 | return call 69 | } 70 | 71 | // Do method 72 | func (call *GetLIFFAllCall) Do() (*LIFFAppsResponse, error) { 73 | res, err := call.c.get(call.ctx, call.c.endpointBase, APIEndpointGetAllLIFFApps, nil) 74 | if err != nil { 75 | return nil, err 76 | } 77 | defer closeResponse(res) 78 | return decodeToLIFFResponse(res) 79 | } 80 | 81 | // AddLIFF method 82 | func (client *Client) AddLIFF(view View) *AddLIFFCall { 83 | return &AddLIFFCall{ 84 | c: client, 85 | view: view, 86 | } 87 | } 88 | 89 | // AddLIFFCall type 90 | type AddLIFFCall struct { 91 | c *Client 92 | ctx context.Context 93 | 94 | view View 95 | } 96 | 97 | // WithContext method 98 | func (call *AddLIFFCall) WithContext(ctx context.Context) *AddLIFFCall { 99 | call.ctx = ctx 100 | return call 101 | } 102 | 103 | func (call *AddLIFFCall) encodeJSON(w io.Writer) error { 104 | enc := json.NewEncoder(w) 105 | return enc.Encode(&struct { 106 | View View `json:"view"` 107 | }{ 108 | View: call.view, 109 | }) 110 | } 111 | 112 | // Do method 113 | func (call *AddLIFFCall) Do() (*LIFFIDResponse, error) { 114 | var buf bytes.Buffer 115 | if err := call.encodeJSON(&buf); err != nil { 116 | return nil, err 117 | } 118 | res, err := call.c.post(call.ctx, APIEndpointAddLIFFApp, &buf) 119 | if err != nil { 120 | return nil, err 121 | } 122 | defer closeResponse(res) 123 | return decodeToLIFFIDResponse(res) 124 | } 125 | 126 | // UpdateLIFF method 127 | func (client *Client) UpdateLIFF(liffID string, view View) *UpdateLIFFCall { 128 | return &UpdateLIFFCall{ 129 | c: client, 130 | liffID: liffID, 131 | view: view, 132 | } 133 | } 134 | 135 | // UpdateLIFFCall type 136 | type UpdateLIFFCall struct { 137 | c *Client 138 | ctx context.Context 139 | 140 | liffID string 141 | view View 142 | } 143 | 144 | // WithContext method 145 | func (call *UpdateLIFFCall) WithContext(ctx context.Context) *UpdateLIFFCall { 146 | call.ctx = ctx 147 | return call 148 | } 149 | 150 | func (call *UpdateLIFFCall) encodeJSON(w io.Writer) error { 151 | enc := json.NewEncoder(w) 152 | return enc.Encode(&struct { 153 | Type LIFFViewType `json:"type"` 154 | URL string `json:"url"` 155 | }{ 156 | Type: call.view.Type, 157 | URL: call.view.URL, 158 | }) 159 | } 160 | 161 | // Do method 162 | func (call *UpdateLIFFCall) Do() (*BasicResponse, error) { 163 | var buf bytes.Buffer 164 | if err := call.encodeJSON(&buf); err != nil { 165 | return nil, err 166 | } 167 | 168 | endpoint := fmt.Sprintf(APIEndpointUpdateLIFFApp, call.liffID) 169 | res, err := call.c.put(call.ctx, endpoint, &buf) 170 | if err != nil { 171 | return nil, err 172 | } 173 | defer closeResponse(res) 174 | return decodeToBasicResponse(res) 175 | } 176 | 177 | // DeleteLIFF method 178 | func (client *Client) DeleteLIFF(liffID string) *DeleteLIFFCall { 179 | return &DeleteLIFFCall{ 180 | c: client, 181 | liffID: liffID, 182 | } 183 | } 184 | 185 | // DeleteLIFFCall type 186 | type DeleteLIFFCall struct { 187 | c *Client 188 | ctx context.Context 189 | 190 | liffID string 191 | } 192 | 193 | // WithContext method 194 | func (call *DeleteLIFFCall) WithContext(ctx context.Context) *DeleteLIFFCall { 195 | call.ctx = ctx 196 | return call 197 | } 198 | 199 | // Do method 200 | func (call *DeleteLIFFCall) Do() (*BasicResponse, error) { 201 | endpoint := fmt.Sprintf(APIEndpointDeleteLIFFApp, call.liffID) 202 | res, err := call.c.delete(call.ctx, endpoint) 203 | if err != nil { 204 | return nil, err 205 | } 206 | defer closeResponse(res) 207 | return decodeToBasicResponse(res) 208 | } 209 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/mention.go: -------------------------------------------------------------------------------- 1 | package linebot 2 | 3 | // Mention type 4 | type Mention struct { 5 | Mentionees []*Mentionee `json:"mentionees"` 6 | } 7 | 8 | // Mentionee type 9 | type Mentionee struct { 10 | Index int `json:"index"` 11 | Length int `json:"length"` 12 | UserID string `json:"userId,omitempty"` 13 | } 14 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/oauth.go: -------------------------------------------------------------------------------- 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 | "context" 19 | "net/url" 20 | "strings" 21 | ) 22 | 23 | // IssueAccessToken method 24 | func (client *Client) IssueAccessToken(channelID, channelSecret string) *IssueAccessTokenCall { 25 | return &IssueAccessTokenCall{ 26 | c: client, 27 | channelID: channelID, 28 | channelSecret: channelSecret, 29 | } 30 | } 31 | 32 | // IssueAccessTokenCall type 33 | type IssueAccessTokenCall struct { 34 | c *Client 35 | ctx context.Context 36 | 37 | channelID string 38 | channelSecret string 39 | } 40 | 41 | // WithContext method 42 | func (call *IssueAccessTokenCall) WithContext(ctx context.Context) *IssueAccessTokenCall { 43 | call.ctx = ctx 44 | return call 45 | } 46 | 47 | // Do method 48 | func (call *IssueAccessTokenCall) Do() (*AccessTokenResponse, error) { 49 | vs := url.Values{} 50 | vs.Set("grant_type", "client_credentials") 51 | vs.Set("client_id", call.channelID) 52 | vs.Set("client_secret", call.channelSecret) 53 | body := strings.NewReader(vs.Encode()) 54 | 55 | res, err := call.c.postForm(call.ctx, APIEndpointIssueAccessToken, body) 56 | if err != nil { 57 | return nil, err 58 | } 59 | defer closeResponse(res) 60 | return decodeToAccessTokenResponse(res) 61 | } 62 | 63 | // RevokeAccessToken method 64 | func (client *Client) RevokeAccessToken(accessToken string) *RevokeAccessTokenCall { 65 | return &RevokeAccessTokenCall{ 66 | c: client, 67 | accessToken: accessToken, 68 | } 69 | } 70 | 71 | // RevokeAccessTokenCall type 72 | type RevokeAccessTokenCall struct { 73 | c *Client 74 | ctx context.Context 75 | 76 | accessToken string 77 | } 78 | 79 | // WithContext method 80 | func (call *RevokeAccessTokenCall) WithContext(ctx context.Context) *RevokeAccessTokenCall { 81 | call.ctx = ctx 82 | return call 83 | } 84 | 85 | // Do method 86 | func (call *RevokeAccessTokenCall) Do() (*BasicResponse, error) { 87 | vs := url.Values{} 88 | vs.Set("access_token", call.accessToken) 89 | body := strings.NewReader(vs.Encode()) 90 | 91 | res, err := call.c.postForm(call.ctx, APIEndpointRevokeAccessToken, body) 92 | if err != nil { 93 | return nil, err 94 | } 95 | defer closeResponse(res) 96 | return decodeToBasicResponse(res) 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/oauth2.go: -------------------------------------------------------------------------------- 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 ( 18 | "context" 19 | "net/url" 20 | "strings" 21 | ) 22 | 23 | const clientAssertionTypeJWT = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer" 24 | 25 | // IssueAccessTokenV2 method 26 | func (client *Client) IssueAccessTokenV2(clientAssertion string) *IssueAccessTokenV2Call { 27 | return &IssueAccessTokenV2Call{ 28 | c: client, 29 | clientAssertion: clientAssertion, 30 | } 31 | } 32 | 33 | // IssueAccessTokenV2Call type 34 | type IssueAccessTokenV2Call struct { 35 | c *Client 36 | ctx context.Context 37 | 38 | clientAssertion string 39 | } 40 | 41 | // WithContext method 42 | func (call *IssueAccessTokenV2Call) WithContext(ctx context.Context) *IssueAccessTokenV2Call { 43 | call.ctx = ctx 44 | return call 45 | } 46 | 47 | // Do method 48 | func (call *IssueAccessTokenV2Call) Do() (*AccessTokenResponse, error) { 49 | vs := url.Values{} 50 | vs.Set("grant_type", "client_credentials") 51 | vs.Set("client_assertion_type", clientAssertionTypeJWT) 52 | vs.Set("client_assertion", call.clientAssertion) 53 | body := strings.NewReader(vs.Encode()) 54 | 55 | res, err := call.c.postForm(call.ctx, APIEndpointIssueAccessTokenV2, body) 56 | if err != nil { 57 | return nil, err 58 | } 59 | defer closeResponse(res) 60 | return decodeToAccessTokenResponse(res) 61 | } 62 | 63 | // GetAccessTokensV2 method 64 | func (client *Client) GetAccessTokensV2(clientAssertion string) *GetAccessTokensV2Call { 65 | return &GetAccessTokensV2Call{ 66 | c: client, 67 | clientAssertion: clientAssertion, 68 | } 69 | } 70 | 71 | // GetAccessTokensV2Call type 72 | type GetAccessTokensV2Call struct { 73 | c *Client 74 | ctx context.Context 75 | 76 | clientAssertion string 77 | } 78 | 79 | // WithContext method 80 | func (call *GetAccessTokensV2Call) WithContext(ctx context.Context) *GetAccessTokensV2Call { 81 | call.ctx = ctx 82 | return call 83 | } 84 | 85 | // Do method 86 | func (call *GetAccessTokensV2Call) Do() (*AccessTokensResponse, error) { 87 | vs := url.Values{} 88 | vs.Set("client_assertion_type", clientAssertionTypeJWT) 89 | vs.Set("client_assertion", call.clientAssertion) 90 | 91 | res, err := call.c.get(call.ctx, call.c.endpointBase, APIEndpointGetAccessTokensV2, vs) 92 | // body := strings.NewReader(vs.Encode()) 93 | // res, err := call.c.postForm(call.ctx, APIEndpointGetAccessTokensV2, body) 94 | if err != nil { 95 | return nil, err 96 | } 97 | defer closeResponse(res) 98 | return decodeToAccessTokensResponse(res) 99 | } 100 | 101 | // RevokeAccessTokenV2 method 102 | func (client *Client) RevokeAccessTokenV2(channelID, channelSecret, accessToken string) *RevokeAccessTokenV2Call { 103 | return &RevokeAccessTokenV2Call{ 104 | c: client, 105 | accessToken: accessToken, 106 | channelID: channelID, 107 | channelSecret: channelSecret, 108 | } 109 | } 110 | 111 | // RevokeAccessTokenV2Call type 112 | type RevokeAccessTokenV2Call struct { 113 | c *Client 114 | ctx context.Context 115 | 116 | accessToken string 117 | channelID string 118 | channelSecret string 119 | } 120 | 121 | // WithContext method 122 | func (call *RevokeAccessTokenV2Call) WithContext(ctx context.Context) *RevokeAccessTokenV2Call { 123 | call.ctx = ctx 124 | return call 125 | } 126 | 127 | // Do method 128 | func (call *RevokeAccessTokenV2Call) Do() (*BasicResponse, error) { 129 | vs := url.Values{} 130 | vs.Set("access_token", call.accessToken) 131 | vs.Set("client_id", call.channelID) 132 | vs.Set("client_secret", call.channelSecret) 133 | body := strings.NewReader(vs.Encode()) 134 | 135 | res, err := call.c.postForm(call.ctx, APIEndpointRevokeAccessTokenV2, body) 136 | if err != nil { 137 | return nil, err 138 | } 139 | defer closeResponse(res) 140 | return decodeToBasicResponse(res) 141 | } 142 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/progress.go: -------------------------------------------------------------------------------- 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 ( 18 | "context" 19 | "fmt" 20 | "net/url" 21 | ) 22 | 23 | // ProgressType type 24 | type ProgressType string 25 | 26 | // ProgressType constants 27 | const ( 28 | ProgressTypeNarrowcast ProgressType = "narrowcast" 29 | ) 30 | 31 | // GetProgressNarrowcastMessages method 32 | func (client *Client) GetProgressNarrowcastMessages(requestID string) *GetProgressMessagesCall { 33 | return &GetProgressMessagesCall{ 34 | c: client, 35 | requestID: requestID, 36 | progressType: ProgressTypeNarrowcast, 37 | } 38 | } 39 | 40 | // GetProgressMessagesCall type 41 | type GetProgressMessagesCall struct { 42 | c *Client 43 | ctx context.Context 44 | 45 | requestID string 46 | progressType ProgressType 47 | } 48 | 49 | // WithContext method 50 | func (call *GetProgressMessagesCall) WithContext(ctx context.Context) *GetProgressMessagesCall { 51 | call.ctx = ctx 52 | return call 53 | } 54 | 55 | // Do method 56 | func (call *GetProgressMessagesCall) Do() (*MessagesProgressResponse, error) { 57 | endpoint := fmt.Sprintf(APIEndpointGetMessageProgress, call.progressType) 58 | var q url.Values 59 | if call.requestID != "" { 60 | q = url.Values{"requestId": []string{call.requestID}} 61 | } 62 | res, err := call.c.get(call.ctx, call.c.endpointBase, endpoint, q) 63 | if err != nil { 64 | return nil, err 65 | } 66 | defer closeResponse(res) 67 | return decodeToMessagesProgressResponse(res) 68 | } 69 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/quick_reply.go: -------------------------------------------------------------------------------- 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 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/raw.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 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 | "context" 19 | "io" 20 | "net/http" 21 | ) 22 | 23 | // NewRawCall method 24 | func (client *Client) NewRawCall(method string, endpoint string) (*RawCall, error) { 25 | req, err := http.NewRequest(method, client.url(client.endpointBase, endpoint), nil) 26 | if err != nil { 27 | return nil, err 28 | } 29 | return &RawCall{ 30 | c: client, 31 | req: req, 32 | }, nil 33 | } 34 | 35 | // NewRawCallWithBody method 36 | func (client *Client) NewRawCallWithBody(method string, endpoint string, body io.Reader) (*RawCall, error) { 37 | req, err := http.NewRequest(method, client.url(client.endpointBase, endpoint), body) 38 | if err != nil { 39 | return nil, err 40 | } 41 | return &RawCall{ 42 | c: client, 43 | req: req, 44 | }, nil 45 | } 46 | 47 | // RawCall type 48 | type RawCall struct { 49 | c *Client 50 | ctx context.Context 51 | 52 | req *http.Request 53 | } 54 | 55 | // AddHeader method 56 | func (call *RawCall) AddHeader(key string, value string) { 57 | call.req.Header.Add(key, value) 58 | } 59 | 60 | // WithContext method 61 | func (call *RawCall) WithContext(ctx context.Context) *RawCall { 62 | call.ctx = ctx 63 | return call 64 | } 65 | 66 | // Do method. Callee must close response object. 67 | func (call *RawCall) Do() (*http.Response, error) { 68 | return call.c.do(call.ctx, call.req) 69 | } 70 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/recipient.go: -------------------------------------------------------------------------------- 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() {} 103 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/send_message.go: -------------------------------------------------------------------------------- 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 | "io" 22 | ) 23 | 24 | // PushMessage method 25 | func (client *Client) PushMessage(to string, messages ...SendingMessage) *PushMessageCall { 26 | return &PushMessageCall{ 27 | c: client, 28 | to: to, 29 | messages: messages, 30 | notificationDisabled: false, 31 | } 32 | } 33 | 34 | // PushMessageCall type 35 | type PushMessageCall struct { 36 | c *Client 37 | ctx context.Context 38 | 39 | to string 40 | messages []SendingMessage 41 | notificationDisabled bool 42 | } 43 | 44 | // WithContext method 45 | func (call *PushMessageCall) WithContext(ctx context.Context) *PushMessageCall { 46 | call.ctx = ctx 47 | return call 48 | } 49 | 50 | // WithNotificationDisabled method will disable push notification 51 | func (call *PushMessageCall) WithNotificationDisabled() *PushMessageCall { 52 | call.notificationDisabled = true 53 | return call 54 | } 55 | 56 | // WithRetryKey method will set retry key string (UUID) on PushMessage. 57 | func (call *PushMessageCall) WithRetryKey(retryKey string) *PushMessageCall { 58 | call.c.setRetryKey(retryKey) 59 | return call 60 | } 61 | 62 | func (call *PushMessageCall) encodeJSON(w io.Writer) error { 63 | enc := json.NewEncoder(w) 64 | return enc.Encode(&struct { 65 | To string `json:"to"` 66 | Messages []SendingMessage `json:"messages"` 67 | NotificationDisabled bool `json:"notificationDisabled,omitempty"` 68 | }{ 69 | To: call.to, 70 | Messages: call.messages, 71 | NotificationDisabled: call.notificationDisabled, 72 | }) 73 | } 74 | 75 | // Do method 76 | func (call *PushMessageCall) Do() (*BasicResponse, error) { 77 | var buf bytes.Buffer 78 | if err := call.encodeJSON(&buf); err != nil { 79 | return nil, err 80 | } 81 | res, err := call.c.post(call.ctx, APIEndpointPushMessage, &buf) 82 | if err != nil { 83 | return nil, err 84 | } 85 | defer closeResponse(res) 86 | return decodeToBasicResponse(res) 87 | } 88 | 89 | // ReplyMessage method 90 | func (client *Client) ReplyMessage(replyToken string, messages ...SendingMessage) *ReplyMessageCall { 91 | return &ReplyMessageCall{ 92 | c: client, 93 | replyToken: replyToken, 94 | messages: messages, 95 | notificationDisabled: false, 96 | } 97 | } 98 | 99 | // ReplyMessageCall type 100 | type ReplyMessageCall struct { 101 | c *Client 102 | ctx context.Context 103 | 104 | replyToken string 105 | messages []SendingMessage 106 | notificationDisabled bool 107 | } 108 | 109 | // WithContext method 110 | func (call *ReplyMessageCall) WithContext(ctx context.Context) *ReplyMessageCall { 111 | call.ctx = ctx 112 | return call 113 | } 114 | 115 | // WithNotificationDisabled method will disable push notification 116 | func (call *ReplyMessageCall) WithNotificationDisabled() *ReplyMessageCall { 117 | call.notificationDisabled = true 118 | return call 119 | } 120 | 121 | func (call *ReplyMessageCall) encodeJSON(w io.Writer) error { 122 | enc := json.NewEncoder(w) 123 | return enc.Encode(&struct { 124 | ReplyToken string `json:"replyToken"` 125 | Messages []SendingMessage `json:"messages"` 126 | NotificationDisabled bool `json:"notificationDisabled,omitempty"` 127 | }{ 128 | ReplyToken: call.replyToken, 129 | Messages: call.messages, 130 | NotificationDisabled: call.notificationDisabled, 131 | }) 132 | } 133 | 134 | // Do method 135 | func (call *ReplyMessageCall) Do() (*BasicResponse, error) { 136 | var buf bytes.Buffer 137 | if err := call.encodeJSON(&buf); err != nil { 138 | return nil, err 139 | } 140 | res, err := call.c.post(call.ctx, APIEndpointReplyMessage, &buf) 141 | if err != nil { 142 | return nil, err 143 | } 144 | defer closeResponse(res) 145 | return decodeToBasicResponse(res) 146 | } 147 | 148 | // Multicast method 149 | func (client *Client) Multicast(to []string, messages ...SendingMessage) *MulticastCall { 150 | return &MulticastCall{ 151 | c: client, 152 | to: to, 153 | messages: messages, 154 | notificationDisabled: false, 155 | } 156 | } 157 | 158 | // MulticastCall type 159 | type MulticastCall struct { 160 | c *Client 161 | ctx context.Context 162 | 163 | to []string 164 | messages []SendingMessage 165 | notificationDisabled bool 166 | } 167 | 168 | // WithContext method 169 | func (call *MulticastCall) WithContext(ctx context.Context) *MulticastCall { 170 | call.ctx = ctx 171 | return call 172 | } 173 | 174 | // WithNotificationDisabled method will disable push notification 175 | func (call *MulticastCall) WithNotificationDisabled() *MulticastCall { 176 | call.notificationDisabled = true 177 | return call 178 | } 179 | 180 | // WithRetryKey method will set retry key string (UUID) on Multicast. 181 | func (call *MulticastCall) WithRetryKey(retryKey string) *MulticastCall { 182 | call.c.setRetryKey(retryKey) 183 | return call 184 | } 185 | 186 | func (call *MulticastCall) encodeJSON(w io.Writer) error { 187 | enc := json.NewEncoder(w) 188 | return enc.Encode(&struct { 189 | To []string `json:"to"` 190 | Messages []SendingMessage `json:"messages"` 191 | NotificationDisabled bool `json:"notificationDisabled,omitempty"` 192 | }{ 193 | To: call.to, 194 | Messages: call.messages, 195 | NotificationDisabled: call.notificationDisabled, 196 | }) 197 | } 198 | 199 | // Do method 200 | func (call *MulticastCall) Do() (*BasicResponse, error) { 201 | var buf bytes.Buffer 202 | if err := call.encodeJSON(&buf); err != nil { 203 | return nil, err 204 | } 205 | res, err := call.c.post(call.ctx, APIEndpointMulticast, &buf) 206 | if err != nil { 207 | return nil, err 208 | } 209 | defer closeResponse(res) 210 | return decodeToBasicResponse(res) 211 | } 212 | 213 | // BroadcastMessage method 214 | func (client *Client) BroadcastMessage(messages ...SendingMessage) *BroadcastMessageCall { 215 | return &BroadcastMessageCall{ 216 | c: client, 217 | messages: messages, 218 | } 219 | } 220 | 221 | // BroadcastMessageCall type 222 | type BroadcastMessageCall struct { 223 | c *Client 224 | ctx context.Context 225 | 226 | messages []SendingMessage 227 | } 228 | 229 | // WithContext method 230 | func (call *BroadcastMessageCall) WithContext(ctx context.Context) *BroadcastMessageCall { 231 | call.ctx = ctx 232 | return call 233 | } 234 | 235 | // WithRetryKey method will set retry key string (UUID) on BroadcastMessage. 236 | func (call *BroadcastMessageCall) WithRetryKey(retryKey string) *BroadcastMessageCall { 237 | call.c.setRetryKey(retryKey) 238 | return call 239 | } 240 | 241 | func (call *BroadcastMessageCall) encodeJSON(w io.Writer) error { 242 | enc := json.NewEncoder(w) 243 | return enc.Encode(&struct { 244 | Messages []SendingMessage `json:"messages"` 245 | }{ 246 | Messages: call.messages, 247 | }) 248 | } 249 | 250 | // Do method 251 | func (call *BroadcastMessageCall) Do() (*BasicResponse, error) { 252 | var buf bytes.Buffer 253 | if err := call.encodeJSON(&buf); err != nil { 254 | return nil, err 255 | } 256 | res, err := call.c.post(call.ctx, APIEndpointBroadcastMessage, &buf) 257 | if err != nil { 258 | return nil, err 259 | } 260 | defer closeResponse(res) 261 | return decodeToBasicResponse(res) 262 | } 263 | 264 | // Narrowcast method 265 | func (client *Client) Narrowcast(messages ...SendingMessage) *NarrowcastCall { 266 | return &NarrowcastCall{ 267 | c: client, 268 | messages: messages, 269 | } 270 | } 271 | 272 | // NarrowcastCall type 273 | type NarrowcastCall struct { 274 | c *Client 275 | ctx context.Context 276 | 277 | messages []SendingMessage 278 | recipient Recipient 279 | filter *Filter 280 | limit *NarrowcastMessageLimit 281 | } 282 | 283 | // Filter type 284 | type Filter struct { 285 | Demographic DemographicFilter `json:"demographic"` 286 | } 287 | 288 | // NarrowcastMessageLimit type 289 | type NarrowcastMessageLimit struct { 290 | Max int `json:"max"` 291 | UpToRemainingQuota bool `json:"upToRemainingQuota,omitempty"` 292 | } 293 | 294 | // WithContext method 295 | func (call *NarrowcastCall) WithContext(ctx context.Context) *NarrowcastCall { 296 | call.ctx = ctx 297 | return call 298 | } 299 | 300 | // WithRecipient method will send to specific recipient objects 301 | func (call *NarrowcastCall) WithRecipient(recipient Recipient) *NarrowcastCall { 302 | call.recipient = recipient 303 | return call 304 | } 305 | 306 | // WithDemographic method will send to specific recipients filter by demographic 307 | func (call *NarrowcastCall) WithDemographic(demographic DemographicFilter) *NarrowcastCall { 308 | call.filter = &Filter{Demographic: demographic} 309 | return call 310 | } 311 | 312 | // WithLimitMax method will set maximum number of recipients 313 | func (call *NarrowcastCall) WithLimitMax(max int) *NarrowcastCall { 314 | call.limit = &NarrowcastMessageLimit{Max: max} 315 | return call 316 | } 317 | 318 | // WithLimitMaxUpToRemainingQuota method will set maximum number of recipients but not over remaining quota. 319 | func (call *NarrowcastCall) WithLimitMaxUpToRemainingQuota(max int, upToRemainingQuota bool) *NarrowcastCall { 320 | call.limit = &NarrowcastMessageLimit{Max: max, UpToRemainingQuota: upToRemainingQuota} 321 | return call 322 | } 323 | 324 | // WithRetryKey method will set retry key string (UUID) on narrowcast. 325 | func (call *NarrowcastCall) WithRetryKey(retryKey string) *NarrowcastCall { 326 | call.c.setRetryKey(retryKey) 327 | return call 328 | } 329 | 330 | func (call *NarrowcastCall) encodeJSON(w io.Writer) error { 331 | enc := json.NewEncoder(w) 332 | return enc.Encode(&struct { 333 | Messages []SendingMessage `json:"messages"` 334 | Recipient Recipient `json:"recipient,omitempty"` 335 | Filter *Filter `json:"filter,omitempty"` 336 | Limit *NarrowcastMessageLimit `json:"limit,omitempty"` 337 | }{ 338 | Messages: call.messages, 339 | Recipient: call.recipient, 340 | Filter: call.filter, 341 | Limit: call.limit, 342 | }) 343 | } 344 | 345 | // Do method 346 | func (call *NarrowcastCall) Do() (*BasicResponse, error) { 347 | var buf bytes.Buffer 348 | if err := call.encodeJSON(&buf); err != nil { 349 | return nil, err 350 | } 351 | res, err := call.c.post(call.ctx, APIEndpointNarrowcast, &buf) 352 | if err != nil { 353 | return nil, err 354 | } 355 | defer closeResponse(res) 356 | return decodeToBasicResponse(res) 357 | } 358 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/sender.go: -------------------------------------------------------------------------------- 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 ( 18 | "encoding/json" 19 | ) 20 | 21 | // Sender type 22 | type Sender struct { 23 | Name string 24 | IconURL string 25 | } 26 | 27 | // MarshalJSON method of QuickReplyButton 28 | func (s *Sender) MarshalJSON() ([]byte, error) { 29 | return json.Marshal(&struct { 30 | Name string `json:"name,omitempty"` 31 | IconURL string `json:"iconUrl,omitempty"` 32 | }{ 33 | Name: s.Name, 34 | IconURL: s.IconURL, 35 | }) 36 | } 37 | 38 | // NewSender function 39 | func NewSender(name, iconURL string) *Sender { 40 | return &Sender{ 41 | Name: name, 42 | IconURL: iconURL, 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/template.go: -------------------------------------------------------------------------------- 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 | "encoding/json" 19 | ) 20 | 21 | // TemplateType type 22 | type TemplateType string 23 | 24 | // TemplateType constants 25 | const ( 26 | TemplateTypeButtons TemplateType = "buttons" 27 | TemplateTypeConfirm TemplateType = "confirm" 28 | TemplateTypeCarousel TemplateType = "carousel" 29 | TemplateTypeImageCarousel TemplateType = "image_carousel" 30 | ) 31 | 32 | // ImageAspectRatioType type 33 | type ImageAspectRatioType string 34 | 35 | // ImageAspectRatioType constants 36 | const ( 37 | ImageAspectRatioTypeRectangle ImageAspectRatioType = "rectangle" 38 | ImageAspectRatioTypeSquare ImageAspectRatioType = "square" 39 | ) 40 | 41 | // ImageSizeType type 42 | type ImageSizeType string 43 | 44 | // ImageSizeType constants 45 | const ( 46 | ImageSizeTypeCover ImageSizeType = "cover" 47 | ImageSizeTypeContain ImageSizeType = "contain" 48 | ) 49 | 50 | // Template interface 51 | type Template interface { 52 | json.Marshaler 53 | Template() 54 | } 55 | 56 | // ButtonsTemplate type 57 | type ButtonsTemplate struct { 58 | ThumbnailImageURL string 59 | ImageAspectRatio ImageAspectRatioType 60 | ImageSize ImageSizeType 61 | ImageBackgroundColor string 62 | Title string 63 | Text string 64 | Actions []TemplateAction 65 | DefaultAction TemplateAction 66 | } 67 | 68 | // MarshalJSON method of ButtonsTemplate 69 | func (t *ButtonsTemplate) MarshalJSON() ([]byte, error) { 70 | return json.Marshal(&struct { 71 | Type TemplateType `json:"type"` 72 | ThumbnailImageURL string `json:"thumbnailImageUrl,omitempty"` 73 | ImageAspectRatio ImageAspectRatioType `json:"imageAspectRatio,omitempty"` 74 | ImageSize ImageSizeType `json:"imageSize,omitempty"` 75 | ImageBackgroundColor string `json:"imageBackgroundColor,omitempty"` 76 | Title string `json:"title,omitempty"` 77 | Text string `json:"text"` 78 | Actions []TemplateAction `json:"actions"` 79 | DefaultAction TemplateAction `json:"defaultAction,omitempty"` 80 | }{ 81 | Type: TemplateTypeButtons, 82 | ThumbnailImageURL: t.ThumbnailImageURL, 83 | ImageAspectRatio: t.ImageAspectRatio, 84 | ImageSize: t.ImageSize, 85 | ImageBackgroundColor: t.ImageBackgroundColor, 86 | Title: t.Title, 87 | Text: t.Text, 88 | Actions: t.Actions, 89 | DefaultAction: t.DefaultAction, 90 | }) 91 | } 92 | 93 | // WithImageOptions method, ButtonsTemplate can set imageAspectRatio, imageSize and imageBackgroundColor 94 | func (t *ButtonsTemplate) WithImageOptions(imageAspectRatio ImageAspectRatioType, imageSize ImageSizeType, imageBackgroundColor string) *ButtonsTemplate { 95 | t.ImageAspectRatio = imageAspectRatio 96 | t.ImageSize = imageSize 97 | t.ImageBackgroundColor = imageBackgroundColor 98 | return t 99 | } 100 | 101 | // WithDefaultAction method, ButtonsTemplate can set defaultAction 102 | func (t *ButtonsTemplate) WithDefaultAction(defaultAction TemplateAction) *ButtonsTemplate { 103 | t.DefaultAction = defaultAction 104 | return t 105 | } 106 | 107 | // ConfirmTemplate type 108 | type ConfirmTemplate struct { 109 | Text string 110 | Actions []TemplateAction 111 | } 112 | 113 | // MarshalJSON method of ConfirmTemplate 114 | func (t *ConfirmTemplate) MarshalJSON() ([]byte, error) { 115 | return json.Marshal(&struct { 116 | Type TemplateType `json:"type"` 117 | Text string `json:"text"` 118 | Actions []TemplateAction `json:"actions"` 119 | }{ 120 | Type: TemplateTypeConfirm, 121 | Text: t.Text, 122 | Actions: t.Actions, 123 | }) 124 | } 125 | 126 | // CarouselTemplate type 127 | type CarouselTemplate struct { 128 | Columns []*CarouselColumn 129 | ImageAspectRatio ImageAspectRatioType 130 | ImageSize ImageSizeType 131 | } 132 | 133 | // CarouselColumn type 134 | type CarouselColumn struct { 135 | ThumbnailImageURL string `json:"thumbnailImageUrl,omitempty"` 136 | ImageBackgroundColor string `json:"imageBackgroundColor,omitempty"` 137 | Title string `json:"title,omitempty"` 138 | Text string `json:"text"` 139 | Actions []TemplateAction `json:"actions"` 140 | DefaultAction TemplateAction `json:"defaultAction,omitempty"` 141 | } 142 | 143 | // MarshalJSON method of CarouselTemplate 144 | func (t *CarouselTemplate) MarshalJSON() ([]byte, error) { 145 | return json.Marshal(&struct { 146 | Type TemplateType `json:"type"` 147 | Columns []*CarouselColumn `json:"columns"` 148 | ImageAspectRatio ImageAspectRatioType `json:"imageAspectRatio,omitempty"` 149 | ImageSize ImageSizeType `json:"imageSize,omitempty"` 150 | }{ 151 | Type: TemplateTypeCarousel, 152 | Columns: t.Columns, 153 | ImageAspectRatio: t.ImageAspectRatio, 154 | ImageSize: t.ImageSize, 155 | }) 156 | } 157 | 158 | // WithImageOptions method, CarouselTemplate can set imageAspectRatio and imageSize 159 | func (t *CarouselTemplate) WithImageOptions(imageAspectRatio ImageAspectRatioType, imageSize ImageSizeType) *CarouselTemplate { 160 | t.ImageAspectRatio = imageAspectRatio 161 | t.ImageSize = imageSize 162 | return t 163 | } 164 | 165 | // WithImageOptions method, CarouselColumn can set imageBackgroundColor 166 | func (t *CarouselColumn) WithImageOptions(imageBackgroundColor string) *CarouselColumn { 167 | t.ImageBackgroundColor = imageBackgroundColor 168 | return t 169 | } 170 | 171 | // WithDefaultAction method, CarouselColumn can set defaultAction 172 | func (t *CarouselColumn) WithDefaultAction(defaultAction TemplateAction) *CarouselColumn { 173 | t.DefaultAction = defaultAction 174 | return t 175 | } 176 | 177 | // ImageCarouselTemplate type 178 | type ImageCarouselTemplate struct { 179 | Columns []*ImageCarouselColumn 180 | } 181 | 182 | // ImageCarouselColumn type 183 | type ImageCarouselColumn struct { 184 | ImageURL string `json:"imageUrl"` 185 | Action TemplateAction `json:"action"` 186 | } 187 | 188 | // MarshalJSON method of ImageCarouselTemplate 189 | func (t *ImageCarouselTemplate) MarshalJSON() ([]byte, error) { 190 | return json.Marshal(&struct { 191 | Type TemplateType `json:"type"` 192 | Columns []*ImageCarouselColumn `json:"columns"` 193 | }{ 194 | Type: TemplateTypeImageCarousel, 195 | Columns: t.Columns, 196 | }) 197 | } 198 | 199 | // Template implements Template interface 200 | func (*ConfirmTemplate) Template() {} 201 | 202 | // Template implements Template interface 203 | func (*ButtonsTemplate) Template() {} 204 | 205 | // Template implements Template interface 206 | func (*CarouselTemplate) Template() {} 207 | 208 | // Template implements Template interface 209 | func (*ImageCarouselTemplate) Template() {} 210 | 211 | // NewConfirmTemplate function 212 | func NewConfirmTemplate(text string, left, right TemplateAction) *ConfirmTemplate { 213 | return &ConfirmTemplate{ 214 | Text: text, 215 | Actions: []TemplateAction{left, right}, 216 | } 217 | } 218 | 219 | // NewButtonsTemplate function 220 | // `thumbnailImageURL` and `title` are optional. they can be empty. 221 | func NewButtonsTemplate(thumbnailImageURL, title, text string, actions ...TemplateAction) *ButtonsTemplate { 222 | return &ButtonsTemplate{ 223 | ThumbnailImageURL: thumbnailImageURL, 224 | Title: title, 225 | Text: text, 226 | Actions: actions, 227 | } 228 | } 229 | 230 | // NewCarouselTemplate function 231 | func NewCarouselTemplate(columns ...*CarouselColumn) *CarouselTemplate { 232 | return &CarouselTemplate{ 233 | Columns: columns, 234 | } 235 | } 236 | 237 | // NewCarouselColumn function 238 | // `thumbnailImageURL` and `title` are optional. they can be empty. 239 | func NewCarouselColumn(thumbnailImageURL, title, text string, actions ...TemplateAction) *CarouselColumn { 240 | return &CarouselColumn{ 241 | ThumbnailImageURL: thumbnailImageURL, 242 | Title: title, 243 | Text: text, 244 | Actions: actions, 245 | } 246 | } 247 | 248 | // NewImageCarouselTemplate function 249 | func NewImageCarouselTemplate(columns ...*ImageCarouselColumn) *ImageCarouselTemplate { 250 | return &ImageCarouselTemplate{ 251 | Columns: columns, 252 | } 253 | } 254 | 255 | // NewImageCarouselColumn function 256 | func NewImageCarouselColumn(imageURL string, action TemplateAction) *ImageCarouselColumn { 257 | return &ImageCarouselColumn{ 258 | ImageURL: imageURL, 259 | Action: action, 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/version.go: -------------------------------------------------------------------------------- 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 | // Don't edit this file directly. This file is generated by script/tag.sh . 16 | 17 | package linebot 18 | 19 | const version = "7.16.0" 20 | -------------------------------------------------------------------------------- /vendor/github.com/line/line-bot-sdk-go/v7/linebot/webhook.go: -------------------------------------------------------------------------------- 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 | "crypto/hmac" 21 | "crypto/sha256" 22 | "encoding/base64" 23 | "encoding/json" 24 | "io" 25 | "io/ioutil" 26 | "net/http" 27 | ) 28 | 29 | // ParseRequest method 30 | func (client *Client) ParseRequest(r *http.Request) ([]*Event, error) { 31 | return ParseRequest(client.channelSecret, r) 32 | } 33 | 34 | // ParseRequest func 35 | func ParseRequest(channelSecret string, r *http.Request) ([]*Event, error) { 36 | defer r.Body.Close() 37 | body, err := ioutil.ReadAll(r.Body) 38 | if err != nil { 39 | return nil, err 40 | } 41 | if !validateSignature(channelSecret, r.Header.Get("X-Line-Signature"), body) { 42 | return nil, ErrInvalidSignature 43 | } 44 | 45 | request := &struct { 46 | Events []*Event `json:"events"` 47 | }{} 48 | if err = json.Unmarshal(body, request); err != nil { 49 | return nil, err 50 | } 51 | return request.Events, nil 52 | } 53 | 54 | func validateSignature(channelSecret, signature string, body []byte) bool { 55 | decoded, err := base64.StdEncoding.DecodeString(signature) 56 | if err != nil { 57 | return false 58 | } 59 | hash := hmac.New(sha256.New, []byte(channelSecret)) 60 | 61 | _, err = hash.Write(body) 62 | if err != nil { 63 | return false 64 | } 65 | 66 | return hmac.Equal(decoded, hash.Sum(nil)) 67 | } 68 | 69 | // GetWebhookInfo method 70 | func (client *Client) GetWebhookInfo() *GetWebhookInfo { 71 | return &GetWebhookInfo{ 72 | c: client, 73 | endpoint: APIEndpointGetWebhookInfo, 74 | } 75 | } 76 | 77 | // GetWebhookInfo type 78 | type GetWebhookInfo struct { 79 | c *Client 80 | ctx context.Context 81 | endpoint string 82 | } 83 | 84 | // WithContext method 85 | func (call *GetWebhookInfo) WithContext(ctx context.Context) *GetWebhookInfo { 86 | call.ctx = ctx 87 | return call 88 | } 89 | 90 | // Do method 91 | func (call *GetWebhookInfo) Do() (*WebhookInfoResponse, error) { 92 | res, err := call.c.get(call.ctx, call.c.endpointBase, call.endpoint, nil) 93 | if err != nil { 94 | return nil, err 95 | } 96 | defer closeResponse(res) 97 | return decodeToWebhookInfoResponse(res) 98 | } 99 | 100 | // TestWebhook type 101 | type TestWebhook struct { 102 | c *Client 103 | ctx context.Context 104 | endpoint string 105 | } 106 | 107 | // SetWebhookEndpointURLCall type 108 | type SetWebhookEndpointURLCall struct { 109 | c *Client 110 | ctx context.Context 111 | 112 | endpoint string 113 | } 114 | 115 | // SetWebhookEndpointURL method 116 | func (client *Client) SetWebhookEndpointURL(webhookEndpoint string) *SetWebhookEndpointURLCall { 117 | return &SetWebhookEndpointURLCall{ 118 | c: client, 119 | endpoint: webhookEndpoint, 120 | } 121 | } 122 | 123 | // WithContext method 124 | func (call *SetWebhookEndpointURLCall) WithContext(ctx context.Context) *SetWebhookEndpointURLCall { 125 | call.ctx = ctx 126 | return call 127 | } 128 | 129 | func (call *SetWebhookEndpointURLCall) encodeJSON(w io.Writer) error { 130 | enc := json.NewEncoder(w) 131 | return enc.Encode(&struct { 132 | Endpoint string `json:"endpoint"` 133 | }{ 134 | Endpoint: call.endpoint, 135 | }) 136 | } 137 | 138 | // Do method 139 | func (call *SetWebhookEndpointURLCall) Do() (*BasicResponse, error) { 140 | var buf bytes.Buffer 141 | if err := call.encodeJSON(&buf); err != nil { 142 | return nil, err 143 | } 144 | res, err := call.c.put(call.ctx, APIEndpointSetWebhookEndpoint, &buf) 145 | if err != nil { 146 | return nil, err 147 | } 148 | defer closeResponse(res) 149 | return decodeToBasicResponse(res) 150 | } 151 | 152 | // TestWebhook method 153 | func (client *Client) TestWebhook() *TestWebhook { 154 | return &TestWebhook{ 155 | c: client, 156 | endpoint: APIEndpointTestWebhook, 157 | } 158 | } 159 | 160 | // WithContext method 161 | func (call *TestWebhook) WithContext(ctx context.Context) *TestWebhook { 162 | call.ctx = ctx 163 | return call 164 | } 165 | 166 | // Do method 167 | func (call *TestWebhook) Do() (*TestWebhookResponse, error) { 168 | res, err := call.c.get(call.ctx, call.c.endpointBase, call.endpoint, nil) 169 | if err != nil { 170 | return nil, err 171 | } 172 | defer closeResponse(res) 173 | return decodeToTestWebhookResponse(res) 174 | } 175 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/kkdai/luis v1.0.1 2 | github.com/kkdai/luis 3 | # github.com/line/line-bot-sdk-go/v7 v7.16.0 4 | github.com/line/line-bot-sdk-go/v7/linebot 5 | --------------------------------------------------------------------------------