n8n-nodes-naver-sms
Version:
Naver Cloud SENS SMS node for n8n
79 lines (78 loc) • 3.04 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NaverSensApi = void 0;
const crypto_1 = __importDefault(require("crypto"));
class NaverSensApi {
constructor() {
this.name = 'naverSensApi';
this.displayName = 'Naver SENS API';
this.documentationUrl = 'https://api.ncloud-docs.com/docs/ai-application-service-sens-smsv2';
this.properties = [
{
displayName: 'Access Key (ncp_iam_으로 시작)',
name: 'accessKey',
type: 'string',
default: '',
required: true,
},
{
displayName: 'Secret Key (40자리 영숫자)',
name: 'secretKey',
type: 'string',
typeOptions: { password: true },
default: '',
required: true,
},
{
displayName: 'Service ID (ncp:sms:kr:로 시작)',
name: 'serviceId',
type: 'string',
default: '',
required: true,
},
{
displayName: 'From (발신번호, 하이픈 없이 숫자만, NAVER 콘솔에 미리 등록해두어야함)',
name: 'from',
type: 'string',
default: '',
required: true,
},
];
}
// 테스트 비활성화 - 실제 사용시에만 검증
// credential 테스트 대신 authenticate 메서드에서 기본 검증 수행
async authenticate(credentials, requestOptions) {
try {
// 필수 파라미터 검증
if (!credentials.accessKey || !credentials.secretKey) {
throw new Error('Access Key와 Secret Key가 필요합니다.');
}
const timestamp = Date.now().toString();
const uri = requestOptions.url || '';
const method = requestOptions.method || 'GET';
// 서명 문자열 생성
const sigStr = `${method.toUpperCase()} ${uri}\n${timestamp}\n${credentials.accessKey}`;
const signature = crypto_1.default
.createHmac('sha256', credentials.secretKey)
.update(sigStr)
.digest('base64');
// 헤더 설정
requestOptions.headers = {
...requestOptions.headers,
'Content-Type': 'application/json; charset=utf-8',
'x-ncp-apigw-timestamp': timestamp,
'x-ncp-iam-access-key': credentials.accessKey,
'x-ncp-apigw-signature-v2': signature,
};
return requestOptions;
}
catch (error) {
console.error('NAVER SENS API 인증 중 오류:', error);
throw error;
}
}
}
exports.NaverSensApi = NaverSensApi;