Firebase - как следить за push-уведомлениями - PullRequest
0 голосов
/ 28 февраля 2019

Я сделал сообщение в API календаря Google, чтобы создать канал уведомлений и следить за изменениями событий:

https://developers.google.com/calendar/v3/push#receiving-notifications

Я использую firebase, как я могу развернутьсайт, который отслеживает сообщения в канале уведомлений, https://example.firebaseapp.com/notifications?

У меня есть простая функция, которая отправляет сообщения в API Google для настройки канала уведомлений:

const functions = require("firebase-functions");

let { google } = require("googleapis");

let privatekey = require("../config.json");
let axios = require("axios");

let jwt = new google.auth.JWT(
    privatekey.client_id,
    null,
    privatekey.private_key,
    ["https://www.googleapis.com/auth/calendar"]
);

let ids = [];
let promises = [];

function revisedRandId() {
     return Math.random().toString(36).replace(/[^a-z]+/g, '').substr(2, 10);
}

async function main() {
    const token = await jwt.authorize();
    console.log("token" + token.access_token);
    let headers = {
        "Access-Control-Allow-Origin": "*",
        "Content-Type": "application/json;charset=UTF-8",
        Authorization: token.token_type + " " + token.access_token
    };
    let data = {
        id: revisedRandId(),
        type: "web_hook",
        address: "https://rguc-calendars.firebaseapp.com/notifications",
        params: {
            ttl: 3600
        }
    };

    axios
        .post(
            "https://www.googleapis.com/calendar/v3/calendars/thirdyear@rguc.co.uk/events/watch",
            data,
            { headers }
        )
        .then(function(response) {
            console.log("success");
        })
        .catch(function(error) {
            console.log(error.response);
        });
}

Как использоватьfirebase чтобы запустить эту функцию и следить за уведомлениями?

...