-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
64 lines (58 loc) · 2.59 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require('notion.php');
require('slack.php');
require('google-drive.php');
require("config.php");
function createLinks($SLACK_BEARER_TOKEN, $notionDbId, $sharedDriveId){
$slackChans = getAllSlackChannels($SLACK_BEARER_TOKEN);
generateNotionLinks($SLACK_BEARER_TOKEN, $slackChans, $notionDbId);
generateGdriveLinks($SLACK_BEARER_TOKEN, $slackChans, $notionDbId, $sharedDriveId);
};
function generateNotionLinks($token, $slack, $notionDbId){
$notion = queryNotionDb($notionDbId);
foreach($notion as $n){
foreach($slack as $s){
if(isset($n["slack-channel"]) && $s["slack-channel-name"] && substr($n["slack-channel"], 1) == $s["slack-channel-name"]){
$target = "notion";
$v= checkBookmarks($token, $s["slack-channel-id"], $target);
if(!$v){
try{
createBookmark($token, $s["slack-channel-id"], $n["notion-url"], $target);
echo("Bookmark notion ".$n["notion-url"]." créé \n");
}catch(Exception $e){
echo("ERROR : Bookmark notion ".$n["notion-url"]." non créé : ".$e."\n");
}
}else{
echo("Bookmark notion : ".$n["notion-url"]." déjà existant\n");
}
}
}
}
}
function generateGdriveLinks($token, $slack, $notionDbId, $sharedDriveId ){
$notion = queryNotionDb($notionDbId);
$gdrive = queryGdrive( $sharedDriveId );
foreach($gdrive as $gd){
foreach($notion as $n){
if(isset($n["gdrive-name"]) && isset($gd["name"]) && $n["gdrive-name"] == $gd["name"] ){
foreach($slack as $s){
if(isset($n["slack-channel"]) && $s["slack-channel-name"] && substr($n["slack-channel"], 1) == $s["slack-channel-name"]){
$target = "gdrive";
$v= checkBookmarks($token, $s["slack-channel-id"], $target);
if(!$v){
try{
createBookmark($token, $s["slack-channel-id"], $gd["url"], $target);
echo("Bookmark gdrive : ".$gd["name"]." créé\n");
}catch(Exception $e){
echo ("ERROR : Bookmark gdrive : ".$gd["name"]." non créé : ".$e."\n");
}
}else{
echo("Bookmark google drive : ".$gd["name"]." déjà existant\n");
}
}
}
}
}
}
}
createLinks($SLACK_BEARER_TOKEN, $notionDbId, $sharedDriveId);