diff --git a/.gitignore b/.gitignore index d6bd546a..49cc346e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -server/firebase-admin.json +server/firebase-admin.*.json node_modules dist .env diff --git a/server/src/endpoints/sendChatMessage.ts b/server/src/endpoints/sendChatMessage.ts index df0610f4..6cf9b122 100644 --- a/server/src/endpoints/sendChatMessage.ts +++ b/server/src/endpoints/sendChatMessage.ts @@ -105,15 +105,25 @@ const sendChatMessage: AuthenticatedEndpointFunction = async (user: User, inputs } log(`Sending to ${user.roomId}: ${message} from ${user.id}`) + const messages = [ + { + groupId: user.roomId, + target: 'chatMessage', + arguments: [inputs.id, user.id, message] + } + ] + + if (user.roomId === 'theater' && message.startsWith('!')) { + console.log('Sending ! message to orb ponderer') + messages.push({ + groupId: 'orbMessages', + target: 'chatMessage', + arguments: [inputs.id, user.id, message] + }) + } return { - messages: [ - { - groupId: user.roomId, - target: 'chatMessage', - arguments: [inputs.id, user.id, message] - } - ], + messages, httpResponse: { status: 200 } } } diff --git a/server/startPonderingOrbs/function.json b/server/startPonderingOrbs/function.json new file mode 100644 index 00000000..a237a7d7 --- /dev/null +++ b/server/startPonderingOrbs/function.json @@ -0,0 +1,32 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "methods": [ + "get" + ] + }, + { + "type": "http", + "direction": "out", + "name": "res" + }, + { + "type": "webPubSubConnection", + "name": "connection", + "hub": "chat", + "userId": "{headers.userid}", + "direction": "in" + }, + { + "type": "webPubSub", + "name": "actions", + "hub": "chat", + "direction": "out" + } + ], + "scriptFile": "../dist/startPonderingOrbs/index.js" +} \ No newline at end of file diff --git a/server/startPonderingOrbs/index.ts b/server/startPonderingOrbs/index.ts new file mode 100644 index 00000000..40a49778 --- /dev/null +++ b/server/startPonderingOrbs/index.ts @@ -0,0 +1,23 @@ +import { AzureFunction, Context, HttpRequest } from '@azure/functions' + +const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest, connection): Promise { + if (req.headers.userId !== process.env.ORB_PONDER_USER) { + context.res = { + status: 401, + body: 'Unauthorized' + } + return + } + + // This never gets undone, but the fact this group always exists is ~fine~ + context.bindings.actions.push({ + actionName: 'addUserToGroup', + userId: req.headers.userId, + group: 'orbMessages' + }) + + context.res = { body: connection } + context.done() +} + +export default httpTrigger diff --git a/server/startPonderingOrbs/sample.dat b/server/startPonderingOrbs/sample.dat new file mode 100644 index 00000000..2e609439 --- /dev/null +++ b/server/startPonderingOrbs/sample.dat @@ -0,0 +1,3 @@ +{ + "name": "Azure" +} \ No newline at end of file