-
Notifications
You must be signed in to change notification settings - Fork 14
image API는 더 이상 사용되지 않습니다. 새로운 storage API로 대체됩니다. #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| 'use strict' | ||
|
|
||
| /** | ||
| * @author Eden Cha <eden@nurigo.net> | ||
| */ | ||
|
|
||
| const qs = require('qs') | ||
| const { asyncRequest } = require('./utils') | ||
| const { getAuth } = require('./config') | ||
|
|
||
| module.exports = class Storage { | ||
| constructor (options = {}) { | ||
| const { fileId } = options | ||
| this.fileId = fileId | ||
| } | ||
|
|
||
| getFileId () { | ||
| return this.fileId | ||
| } | ||
|
|
||
| setFileId (fileId) { | ||
| this.fileId = fileId | ||
| } | ||
|
|
||
| /** | ||
| * 파일 업로드 | ||
| * | ||
| * @param {object} params - 서버 요청 시 사용되는 파라미터 입니다. | ||
| * @example | ||
| * // return promise object | ||
| * Storage.upload({ | ||
| * type: '파일 타입' | ||
| * }).then(body => { | ||
| * console.log(body) | ||
| * }) | ||
| */ | ||
| upload (params = {}) { | ||
| const { file, name, type, link } = params | ||
| return asyncRequest('post', 'https://api.solapi.com/storage/v1/files', { | ||
| headers: { Authorization: getAuth() }, | ||
| form: { file, name, type, link } | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * 업로드 된 파일 조회 | ||
| * | ||
| * @param {object} params - 서버 요청 시 사용되는 파라미터 입니다. | ||
| * @example | ||
| * // return promise object | ||
| * Storage.get({ | ||
| * fileId: '이미지 아이디 ' | ||
| * }).then(body => { | ||
| * console.log(body) | ||
| * }) | ||
| */ | ||
| get (params = {}) { | ||
| const queryString = qs.stringify({ fileId: this.fileId, ...params }) | ||
| const uri = 'https://api.solapi.com/storage/v1/files' | ||
| return asyncRequest('get', uri + (queryString ? '?' + queryString : ''), { | ||
| headers: { Authorization: getAuth() } | ||
| }) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| const { config, Group } = require('../') | ||
| config.init({ | ||
| // https://solapi.com/credentials | ||
| apiKey: 'ENTER_YOUR_API_KEY', | ||
| apiSecret: 'ENTER_YOUR_API_SECRET' | ||
| }) | ||
| const messageParams = { | ||
| type: 'ATA', | ||
| subject: 'this is ATA', | ||
| text: 'Hello, this is ATA', | ||
| to: '수신 번호', | ||
| // https://solapi.com/senderids | ||
| from: '발신 번호', | ||
| kakaoOptions: { | ||
| disableSms: true, | ||
| // https://solapi.com/kakao/plus-friends | ||
| pfId: 'ENTER_YOUR_PFID', | ||
| // https://solapi.com/kakao/templates | ||
| templateId: 'ENTER_YOUR_TEMPLATE_ID', | ||
| buttons: [ | ||
| { | ||
| buttonName: 'YOUR_BUTTON_NAME', | ||
| buttonType: 'YOUR_BUTTON_TYPE', | ||
| linkMo: 'YOUR_BUTTON_LINK', | ||
| linkPc: 'YOUR_BUTTON_LINK', | ||
| linkAnd: 'YOUR_BUTTON_LINK', | ||
| linkIos: 'YOUR_BUTTON_LINK' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| // send ATA (알림톡) | ||
| main() | ||
|
|
||
| async function main () { | ||
| try { | ||
| const response = await send(messageParams) | ||
| console.info(response) | ||
| } catch (error) { | ||
| console.error(error) | ||
| } | ||
| } | ||
|
|
||
| function send (params, agent = {}) { | ||
| return Group.sendSimpleMessage(params, agent) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| const path = require('path') | ||
| const image2base64 = require('image-to-base64') | ||
| const { config, Group, Storage } = require('../') | ||
| config.init({ | ||
| apiKey: 'ENTER_YOUR_API_KEY', | ||
| apiSecret: 'ENTER_YOUR_API_SECRET' | ||
| }) | ||
| const options = { | ||
| imagePath: path.join(__dirname, '/source/tmp_img.png') | ||
| } | ||
| const storageParams = { | ||
| // https://solapi.com/storage | ||
| fileId: 'ENTER_YOUR_FILE_ID', | ||
| name: 'ENTER_YOUR_IMAGE_NAME', | ||
| link: 'ENTER_YOUR_IMAGE_LINK', | ||
| type: 'KAKAO' | ||
| } | ||
| const messageParams = { | ||
| type: 'CTI', | ||
| subject: 'this is CTI', | ||
| text: 'Hello, this is CTI', | ||
| to: '수신 번호', | ||
| from: '발신 번호', | ||
| kakaoOptions: { | ||
| disableSms: true, | ||
| // https://solapi.com/kakao/plus-friends | ||
| pfId: 'ENTER_YOUR_PFID', | ||
| imageId: storageParams.fileId, | ||
| buttons: [ | ||
| { | ||
| buttonName: '홈페이지', | ||
| buttonType: 'WL', | ||
| linkMo: 'https://solapi.com', | ||
| linkPc: 'https://solapi.com' | ||
| }, | ||
| { | ||
| buttonName: '회원가입', | ||
| buttonType: 'WL', | ||
| linkMo: 'https://solapi.com/signup', | ||
| linkPc: 'https://solapi.com/signup' | ||
| } | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| // send CTI (친구톡 이미지) | ||
| const { fileId } = storageParams | ||
| const storage = new Storage({ fileId }) | ||
| main() | ||
|
|
||
| async function main () { | ||
| try { | ||
| const { fileList = [] } = await getImages({ fileId: storage.getFileId() }) | ||
| const image = fileList[0] || {} | ||
| if (!image.fileId) { | ||
| const { imagePath } = options | ||
| const { type, name, link } = storageParams | ||
| const imageOptions = { type, name, link } | ||
| const response = await uploadImage(imagePath, imageOptions) | ||
| storage.setFileId(response.fileId) | ||
| } | ||
| messageParams.kakaoOptions.imageId = storage.getFileId() | ||
| const response = await send(messageParams) | ||
| console.info(response) | ||
| } catch (error) { | ||
| console.error(error) | ||
| } | ||
| } | ||
|
|
||
| function uploadImage (path, params) { | ||
| return new Promise((resolve, reject) => { | ||
| image2base64(path).then(file => { | ||
| storage | ||
| .upload({ file, ...params }) | ||
| .then(resolve) | ||
| .catch(reject) | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| function getImages (params) { | ||
| return new Promise((resolve, reject) => { | ||
| storage | ||
| .get(params) | ||
| .then(resolve) | ||
| .catch(reject) | ||
| }) | ||
| } | ||
|
|
||
| function send (params, agent = {}) { | ||
| return Group.sendSimpleMessage(params, agent) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| const path = require('path') | ||
| const image2base64 = require('image-to-base64') | ||
| const { config, Group, Storage } = require('../') | ||
| config.init({ | ||
| // https://solapi.com/credentials | ||
| apiKey: 'ENTER_YOUR_API_KEY', | ||
| apiSecret: 'ENTER_YOUR_API_SECRET' | ||
| }) | ||
| const options = { | ||
| imagePath: path.join(__dirname, '/source/tmp_img.png') | ||
| } | ||
| const storageParams = { | ||
| // https://solapi.com/storage | ||
| fileId: 'ENTER_YOUR_FILE_ID', | ||
| type: 'MMS' | ||
| } | ||
| const messageParams = { | ||
| type: 'MMS', | ||
| subject: 'this is MMS', | ||
| text: 'Hello, this is MMS', | ||
| to: '수신 번호', | ||
| // https://solapi.com/senderids | ||
| from: '발신 번호', | ||
| imageId: storageParams.fileId | ||
| } | ||
|
|
||
| // send MMS (멀티미디어메시지) | ||
| const { fileId } = storageParams | ||
| const storage = new Storage({ fileId }) | ||
| main() | ||
|
|
||
| async function main () { | ||
| try { | ||
| const { fileList = [] } = await getImages({ fileId: storage.getFileId() }) | ||
| const image = fileList[0] || {} | ||
| if (!image.fileId) { | ||
| const { imagePath } = options | ||
| const { type } = storageParams | ||
| const imageOptions = { type } | ||
| const response = await uploadImage(imagePath, imageOptions) | ||
| storage.setFileId(response.fileId) | ||
| } | ||
| messageParams.imageId = storage.getFileId() | ||
| const response = await send(messageParams) | ||
| console.info(response) | ||
| } catch (error) { | ||
| console.error(error) | ||
| } | ||
| } | ||
|
|
||
| function uploadImage (path, params) { | ||
| return new Promise((resolve, reject) => { | ||
| image2base64(path).then(file => { | ||
| storage | ||
| .upload({ file, ...params }) | ||
| .then(resolve) | ||
| .catch(reject) | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| function getImages (params) { | ||
| return new Promise((resolve, reject) => { | ||
| storage | ||
| .get(params) | ||
| .then(resolve) | ||
| .catch(reject) | ||
| }) | ||
| } | ||
|
|
||
| function send (params, agent = {}) { | ||
| return Group.sendSimpleMessage(params, agent) | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
띄어쓰기