Created
January 20, 2025 08:40
-
-
Save marcelklehr/5755eeafbd781ffc158c02451338a896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as wmill from "npm:windmill-client@1" | |
import axios from "npm:axios" | |
export async function main( | |
nextcloudResource: string, | |
userId: string|null = null, | |
notificationUserId: string, | |
subject: string, | |
message: string = '', | |
subjectParameters: object = {}, | |
messageParameters: object = {}, | |
useAppApiAuth: boolean = false, | |
) { | |
const ncResource = await wmill.getResource( | |
nextcloudResource, | |
); | |
const data = { | |
subject, | |
message, | |
subjectParameters, | |
messageParameters, | |
} | |
const url = ncResource.baseUrl + '/ocs/v2.php/apps/notifications/api/v3/admin_notifications/' + notificationUserId | |
const config = { | |
...(!useAppApiAuth && ({ | |
auth: { | |
username: ncResource.username, | |
password: ncResource.password, | |
}, | |
})), | |
headers: { | |
'content-type': 'application/json', | |
'ocs-apirequest': true, | |
...(useAppApiAuth && ({ | |
"AA-VERSION": "2.3.0", | |
"EX-APP-ID": "windmill_app", | |
"EX-APP-VERSION": "1.0.0", | |
"AUTHORIZATION-APP-API": btoa( | |
`${userId || ncResource.username}:${ncResource.password}`, | |
), | |
})), | |
}, | |
} | |
console.debug('config', config) | |
try { | |
const response = await axios.post(url, data, config) | |
console.debug('RESPONSE', response.data) | |
return { | |
response: response.data | |
} | |
} catch(e) { | |
console.debug('error', e) | |
} | |
return {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment