Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최현준
/
도와줘요 채팅맨
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
1
Network
Create a new issue
Commits
Issue Boards
Authored by
최현준
2020-06-02 12:33:59 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9340b1c88c9c850485de19f413fb3187cc558d20
9340b1c8
1 parent
ecc916bd
개인별 언어 저장추가
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
33 deletions
app.js
app.js
View file @
9340b1c
...
...
@@ -40,6 +40,12 @@ userinfo[0] =
userInLn
:
'userInLn'
,
userPaLn
:
'userPaLn'
}
userinfo
[
1
]
=
{
userId
:
'userId'
,
userInLn
:
'userInLn'
,
userPaLn
:
'userPaLn'
}
app
.
use
(
bodyParser
.
json
());
...
...
@@ -48,8 +54,10 @@ app.post('/hook', function (req, res) {
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
var
In
ln
=
message
.
text
;
// input message
var
In
putMessage
=
message
.
text
;
// input message
var
LnCh
=
1
;
// Language change attempt => value 0;
var
user_id
=
eventObj
.
source
.
userId
;
var
NumberLock
=
0
;
// request log
// console.log('======================', new Date() ,'======================');
...
...
@@ -60,24 +68,77 @@ app.post('/hook', function (req, res) {
// console.log('my meesage: ', message.text);
// console.log('my ip check: ', req.ip);
for
(
var
i
in
userinfo
)
{
console
.
log
(
'i값 출력'
,
i
);
console
.
log
(
'userinfolength'
,
userinfo
.
length
);
if
(
userinfo
[
i
].
userId
==
user_id
)
{
console
.
log
(
'동일한 id 존재.'
);
NumberLock
=
i
;
break
;
}
else
if
(
i
==
userinfo
.
length
-
1
)
{
console
.
log
(
'동일한 것이 존재하지 않습니다. 새로운 개체를 생성합니다.'
);
userinfo
[
i
+
1
]
=
{
userId
:
user_id
,
userInLn
:
'en'
,
userPaLn
:
'en'
//default value
}
NumberLock
=
i
+
1
;
}
}
for
(
var
i
in
lnDetec
)
// Detect Language change
{
if
(
In
ln
==
lnDetec
[
i
].
InLn
)
if
(
In
putMessage
==
lnDetec
[
i
].
InLn
)
{
l
n
=
lnDetec
[
i
].
PaLn
;
userinfo
[
NumberLock
].
userPaL
n
=
lnDetec
[
i
].
PaLn
;
LnCh
=
0
;
}
}
if
(
LnCh
)
// if there is no attempt to change language then call operators
{
detector
(
message
.
text
);
trans
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
detector
(
message
.
text
,
NumberLock
);
trans
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
,
NumberLock
);
}
res
.
sendStatus
(
200
);
});
function
trans
(
replyToken
,
message
)
{
function
detector
(
message
,
NumberLock
)
{
request
.
post
(
{
url
:
PAPAGO_D_URL
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'X-Naver-Client-Id'
:
`
${
PAPAGO_ID
}
`
,
'X-Naver-Client-Secret'
:
`
${
PAPAGO_SECRET
}
`
},
body
:
'query='
+
message
,
json
:
true
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
console
.
log
(
'[넘어온 메시지]'
,
message
);
console
.
log
(
'[객체 정보 확인]'
,
body
);
console
.
log
(
'[user 객체 정보 확인]'
,
userinfo
[
NumberLock
]);
console
.
log
(
'[NumberLock value?]'
,
NumberLock
);
//tempc = body.langCode;
//userinfo에 user입력 language언어 감지 및 저장
userinfo
[
NumberLock
].
userInLn
=
body
.
langCode
;
}
}
)
}
function
trans
(
replyToken
,
message
,
NumberLock
)
{
request
.
post
(
{
...
...
@@ -88,7 +149,7 @@ function trans(replyToken, message) {
'X-Naver-Client-Secret'
:
`
${
PAPAGO_SECRET
}
`
},
//body: 'source=ko&target='+ln+'&text=' + message,
body
:
'source='
+
tempc
+
'&target='
+
l
n
+
'&text='
+
message
,
body
:
'source='
+
userinfo
[
NumberLock
].
userInLn
+
'&target='
+
userinfo
[
NumberLock
].
userPaL
n
+
'&text='
+
message
,
json
:
true
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
...
...
@@ -114,34 +175,9 @@ function trans(replyToken, message) {
});
}
});
}
function
detector
(
message
)
{
request
.
post
(
{
url
:
PAPAGO_D_URL
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'X-Naver-Client-Id'
:
`
${
PAPAGO_ID
}
`
,
'X-Naver-Client-Secret'
:
`
${
PAPAGO_SECRET
}
`
},
body
:
'query='
+
message
,
json
:
true
},(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
console
.
log
(
'[넘어온 메시지]'
,
message
);
console
.
log
(
'[객체 정보 확인]'
,
body
);
tempc
=
body
.
langCode
;
}
}
)
}
// try {
// const option = {
// ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
...
...
Please
register
or
login
to post a comment