Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
happy-botday
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guillaume Vagner
happy-botday
Commits
67d9ea68
Commit
67d9ea68
authored
6 years ago
by
Guillaume Vagner
Browse files
Options
Downloads
Patches
Plain Diff
add-/birthdays
parent
7f967c34
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
index.js
+1
-36
1 addition, 36 deletions
index.js
requests.js
+34
-0
34 additions, 0 deletions
requests.js
telegram.js
+17
-0
17 additions, 0 deletions
telegram.js
with
52 additions
and
36 deletions
index.js
+
1
−
36
View file @
67d9ea68
const
bot
=
require
(
'
./telegram
'
);
const
bot
=
require
(
'
./telegram
'
);
const
app
=
require
(
'
./website
'
);
const
app
=
require
(
'
./website
'
);
const
mongoose
=
require
(
'
./mongoose
'
);
const
mongoose
=
require
(
'
./mongoose
'
);
const
{
sendRequest
,
getBirthdays
}
=
require
(
'
./requests
'
);
const
Token
=
require
(
'
./models/Token
'
);
const
Token
=
require
(
'
./models/Token
'
);
const
rp
=
require
(
'
request-promise
'
);
function
sendRequest
(
req
,
token
,
callback
)
{
const
options
=
{
headers
:
{
'
Authorization
'
:
`Bearer
${
token
}
`
},
json
:
true
}
const
url
=
'
https://gateway.linkcs.fr/v1/graphql
'
;
return
rp
(
`
${
url
}
?query=
${
req
}
`
,
options
)
}
function
getBirthdays
(
token
)
{
req
=
'
query getUsersBirthday {users: usersBirthday { ...userData}}fragment userData on User {id firstName lastName roles {sector {composition {association {id}}}}}
'
return
sendRequest
(
req
,
token
).
then
(
body
=>
{
const
users
=
[];
body
.
data
.
users
.
forEach
(
user
=>
{
use
=
{};
use
.
name
=
`
${
user
.
firstName
}
${
user
.
lastName
}
`
;
use
.
asso
=
[];
user
.
roles
.
forEach
(
role
=>
{
use
.
asso
.
push
(
role
.
sector
.
composition
.
association
.
id
);
})
users
.
push
(
use
);
});
return
users
;
})
}
// Token.findOne({ expiration: { $gt: Date.now() } }).then(token => {
// getBirthdays(token.token).then(a => console.log(a));
// })
\ No newline at end of file
This diff is collapsed.
Click to expand it.
requests.js
0 → 100644
+
34
−
0
View file @
67d9ea68
const
rp
=
require
(
'
request-promise
'
);
const
Token
=
require
(
'
./models/Token
'
);
function
sendRequest
(
req
,
token
,
callback
)
{
const
options
=
{
headers
:
{
'
Authorization
'
:
`Bearer
${
token
}
`
},
json
:
true
}
const
url
=
'
https://gateway.linkcs.fr/v1/graphql
'
;
return
rp
(
`
${
url
}
?query=
${
req
}
`
,
options
)
}
function
getBirthdays
(
token
)
{
req
=
'
query getUsersBirthday {users: usersBirthday { ...userData}}fragment userData on User {id firstName lastName roles {sector {composition {association {id}}}}}
'
return
sendRequest
(
req
,
token
).
then
(
body
=>
{
const
users
=
[];
body
.
data
.
users
.
forEach
(
user
=>
{
use
=
{};
use
.
name
=
`
${
user
.
firstName
}
${
user
.
lastName
}
`
;
use
.
asso
=
[];
user
.
roles
.
forEach
(
role
=>
{
use
.
asso
.
push
(
role
.
sector
.
composition
.
association
.
id
);
})
users
.
push
(
use
);
});
return
users
;
})
}
module
.
exports
=
{
getBirthdays
,
sendRequest
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
telegram.js
+
17
−
0
View file @
67d9ea68
...
@@ -3,6 +3,7 @@ const TelegramBot = require('node-telegram-bot-api');
...
@@ -3,6 +3,7 @@ const TelegramBot = require('node-telegram-bot-api');
const
Token
=
require
(
'
./models/Token
'
);
const
Token
=
require
(
'
./models/Token
'
);
const
config
=
require
(
'
./config
'
);
const
config
=
require
(
'
./config
'
);
const
{
sendRequest
,
getBirthdays
}
=
require
(
'
./requests
'
);
const
bot
=
new
TelegramBot
(
config
.
telegram
.
token
,
{
polling
:
true
});
const
bot
=
new
TelegramBot
(
config
.
telegram
.
token
,
{
polling
:
true
});
...
@@ -53,4 +54,20 @@ bot.onText(/\/disconnect/, (msg, _) => {
...
@@ -53,4 +54,20 @@ bot.onText(/\/disconnect/, (msg, _) => {
})
})
});
});
bot
.
onText
(
/
\/
birthdays/
,
(
msg
,
_
)
=>
{
const
chatId
=
msg
.
chat
.
id
;
Token
.
findOne
({
chatId
:
chatId
,
expiration
:
{
$gt
:
Date
.
now
()
}
}).
then
(
token
=>
{
return
getBirthdays
(
token
.
token
)
}).
then
(
users
=>
{
var
msg
=
'
Joyeux anniversaire à :
\n
'
users
.
forEach
(
user
=>
{
msg
+=
`
${
user
.
name
}
\n`
});
bot
.
sendMessage
(
chatId
,
msg
);
})
});
module
.
exports
=
bot
;
module
.
exports
=
bot
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment