Git Product home page Git Product logo

ncpclient's Introduction

NCP-Client

npm version travisici install size npm downloads

An easy-to-use typescript wrapper for Naver Cloud Platform API. With VersionUps, API wrappers will be added and updates.

Notice ) Always welcome contributions for user's Productivity

Table of Contents

Dependency

  • axios

Installation

with npm

$ npm install ncp-client

Usage

Import API Wrapper

var { SENS, PAPAGO } = require('ncp-client')

[ SENS ] SMS API

  • Common
// type your NCP API Authentication key pair
const ncpAuthKey = {
    accessKey: 'accessKey',
    secretKey: 'secretKey',
}
// type your SMS service key pair
const smsAuthKey = {
    phone: 'phoneNumber',
    serviceId: 'serviceId'
}
// create SENS api container and get smsService agent.
const sens = new SENS()
const smsService = sens.smsService(ncpAuthKey, smsAuthKey)
  • SMS Send

    // type your SMS send parameter 
    const sendSMSparam = {
        to: 'recipient phoneNumber',
        content: 'message to send'
    }
    // to send to multiple people 
    const multipleSMSparam = [
      { to: 'r1', content: 'c1'},
      { to: 'r2', content: 'c2'},
      { to: 'r3', content: 'c3'}
    ]
    
    async function sendMessage() {
      	// if you don't pass countryCode, default countryCode is 82.
        const {isSuccess, data, preprocessed, errorMessage } = await smsService.sendSMS( sendSMSparam, countryCode )
        // write something after async function
        if (isSuccess) {
          	const { result, requestId } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }
  • Search message delivery request

    async function searchMessageDeliveryRequest(requestId: string) {
        const {isSuccess, data, preprocessed, errorMessage } = await smsService.searchMessageRequest(requestId)
        // write something after async function
        if (isSuccess) {
          	// messageIds: string[]
          	const { result, requestId, messageIds } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }
  • Search message delivery results

    async function searchMessageDeliveryResults(messageId: string) {
        const {isSuccess, data, preprocessed, errorMessage } = await smsService.searchMessageResult(messageId)
        // write something after async function
        if (isSuccess) {
          	// messages: MessageResultType[]
          	const { result, messages } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }

[ NaverOpenAPI ] Papago NMT API

  • Common
// type your NaverOpenAPI Client key pair
let openApiClientAuth = {
    clientId: 'clientId',
    clientSecret: 'clientSecret'
}
// create NaverOpenAPI api container and get papagoService agent.
const naverOpenAPI = new NaverOpenAPI()
const papagoClient = naverOpenAPI.papagoService(openApiClientAuth)
  • Translation

    async function translation(source: string, target: string, text: string) {
        const { isSuccess, data, preprocessed, errorMessage } = await papagoClient.translation(src, target, text)
        // write something after async function
        if (isSuccess) {
          	const { source, target, translated } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }
  • Language Detection

    async function detectLanguage(text: string) {
        const { isSuccess, data, preprocessed, errorMessage } = await papagoClient.detectLanguage(text)
        // write something after async function
        if (isSuccess) {
          	const { detected } = preprocessed
            // do something with data
        } else {
            // handle with errorMessage
        }
    }
  • Korean Name Romanizer

    async function koreanNameRomanizer(koreanName: string) {
        const { isSuccess, data, preprocessed, errorMessage } = await papagoClient.koreanNameRominizer(name)
      	// write something after async function
        if (isSuccess) {
          	const { firstName, bestMatched } = preprocessed
          	// do something with data
        } else {
            // handle with errorMessage
        }
    }

Types

Note) Introduced types are what you have to create or handle in use NCP-Client

Based on Typescript's type alias, several types for api are declared. At this step, you can only show what you will use at each usage.

Common & Authentification

// NCP api authentication key pair
type NCPAuthKeyType = {
  accessKey: string
  secretKey: string
}

// Naver Open API client key pair
export type NaverOpenApiAuthType = {
  clientId: string
  clientSecret: string
}

// Common return value for all NCP api request
type ApiClientResponse<T> = {
  isSuccess: boolean
  // If success, handle with it
  data?: T
  // If failed, handle with it
  errorMessage?: {}
}

( SENS ) SMS

  • Send SMS

    type SendSMSParamType = {
      // `to` is recipient's phone number
      to:	string
      // `content` is text content what you want to send
      content:	string
    }
    
    type SendSMSReturnType = {
      // `statusCode` and `statusText` are the HTTP status code / message from the server response
      statusCode: string
      statusText: string
      // `requestId` represents current succesful request's key, `requestTime` represents Datetime string
      requestId:	string
      requestTime: string
    }
  • Search message delivery request

    export type SearchMessageRequestReturnType = {
      requestId: string
      statusCode: string
      statusName: string
      // `messages` contains messages associated with requestId
      messages: MessageRequestType[]
    }
    // Each message's summary
    type MessageRequestType = {
      messageId: string
      requestTime: string
      contentType: string
      countryCode: string
      from: string
      to: string
    }
  • Search message delivery results

    export type SearchMessageResultReturnType = {
      statusCode: string
      statusName: string
      // `messages` contains messages associated with messageId
      messages: MessageResultType[]
    }
    // Each message's detail
    type MessageResultType = {
      requestTime: string
      // `contentType` will be 'COMM' | 'AD', but currently not supported with AD message api
      contentType: string
      content: string
      countryCode: string
      from: string
      to: string
      status: string
      statusCode: string
      statusMessage: string
      statusName: string
      // `completeTime` means the time when request completed
      completeTime: string
      // `telcoCode` means telecommunication Provider Info
      telcoCode: string
    }

( NaverOpenAPI ) Papago NMT

  • Translation

    export type PapagoTranslationReturnType = {
      message: PapagoTranslationMessageType
    }
    type PapagoTranslationMessageType = {
      // current Papago NMT responses
      '@type': string,
      '@service': string,
      '@version': string,
      result: PapagoTranslationResultType
    }
    // translation Report
    type PapagoTranslationResultType = {
      srcLangType: string
      tarLangType: string
      translatedText: string
    }
  • Language Detection

    export type PapagoDetectLanguageReturnType = {
      // detected language code from api
      langCode: string
    }
  • Korean Name Romanizer

    export type PapagoKoreanNameRomanizerReturnType = {
      aResult : PapagoKoreanNameRomanizerResultType[]
    }
    type PapagoKoreanNameRomanizerResultType = {
      // detected firstName
      sFirstName: string
      // array of romanized names
      aItems: PapagoKoreanNameRomanizerItemType[]
    }
    type PapagoKoreanNameRomanizerItemType = {
      // romanized korean name
      name: string
      // frequency integer values
      score: string
    }

API Response statuses

API Response status provided by Naver Cloud Platform

HTTP Status Desc
202 Accept (Successfully requested)
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
429 Too Many Requests
500 Internal Server Error

Current Support

(SENS) SMS API v2

  • Send SMS
  • Search message delivery request
  • Search message delivery results

(NaverOpenAPI) Papago NMT API v1

  • Translation
  • Language Detection
  • Korean Name Romanizer

Credits

License

MIT License

ncpclient's People

Contributors

hubtwork avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

shimseongbo

ncpclient's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.