点击通过Firebase for Firebase

时间:2017-04-11 09:45:27

标签: firebase firebase-cloud-messaging google-cloud-functions

我有一个使用firebase作为后端的Android应用程序。

一旦数据库在特定节点发生变化,使用 firebase云功能,通知就会触发。

但我无法弄清楚如何根据特定节点的变化打开特定活动。

我在数据库中有5个活动和5个节点,应该通过通知打开的活动应该是与特定节点上的更改相对应的活动。

但是现在它会打开默认活动。

我无法确定通知如何包含在其有效负载中打开特定活动的信息,因为通知是通过firebase云功能提供的。

index.js的示例文件粘贴在下面,仅用于一个子节点的更改。

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);


exports.sendPowerNotification = functions.database.ref("/Matrimony").onWrite((event) => {
    const data = event.data;
    console.log('New Issue added');
    if (!data.changed()) {
        return;
    }
    const status = data.val();
    //const onOff =  status ? "on": "off";
    const author = event.params.author;
        const name = author.val();

    const payload = {
        notification: {
            title: 'SahuSmaj : New Matrimony Post',
            body: `New biodata entered,check it out`,
            sound: "default"
            click_action: "MATRIMONY"
        }
    };

    const options = {
        priority: "high",
        timeToLive: 60 * 60 * 24 //24 hours
    };
    console.log('Sending notifications');
    return admin.messaging().sendToTopic("matrimony", payload, options);

});

执行上面的代码会显示以下错误:

    Error: Error occurred while parsing your function triggers.

/private/var/folders/sf/2spqs2n1493d506bj06wj0zw0000gn/T/fbfn_1018VUGx2TTMO1y8/index.js:33
            click_action : "MATRIMONY"
            ^^^^^^^^^^^^
SyntaxError: Unexpected identifier
    at Object.exports.runInThisContext (vm.js:76:16)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js:16:9)
    at Module._compile (module.js:570:32)

我已在 AndroidManifest.xml 中进行了更改,以使用 Android过滤器打开特定通知。

        <intent-filter>
            <action android:name="MATRIMONY" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

1 个答案:

答案 0 :(得分:1)

<Window...> <Window.Resources> <Style x:Key="FocusVisual"> <Setter Property="Control.Template"> <Setter.Value> <ControlTemplate> <Rectangle Margin="2" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/> </ControlTemplate> </Setter.Value> </Setter> </Style> <SolidColorBrush x:Key="Button.Static.Background" Color="#FFDDDDDD"/> <SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/> <SolidColorBrush x:Key="Button.MouseOver.Background" Color="#FFBEE6FD"/> <SolidColorBrush x:Key="Button.MouseOver.Border" Color="#FF3C7FB1"/> <SolidColorBrush x:Key="Button.Pressed.Background" Color="Red"/> <SolidColorBrush x:Key="Button.Pressed.Border" Color="#FF2C628B"/> <SolidColorBrush x:Key="Button.Disabled.Background" Color="#FFF4F4F4"/> <SolidColorBrush x:Key="Button.Disabled.Border" Color="#FFADB2B5"/> <SolidColorBrush x:Key="Button.Disabled.Foreground" Color="#FF838383"/> <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}"> <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/> <Setter Property="Background" Value="{StaticResource Button.Static.Background}"/> <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/> <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="HorizontalContentAlignment" Value="Center"/> <Setter Property="VerticalContentAlignment" Value="Center"/> <Setter Property="Padding" Value="1"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type Button}"> <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="true"> <ContentPresenter x:Name="contentPresenter" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> </Border> <ControlTemplate.Triggers> <Trigger Property="IsDefaulted" Value="true"> <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/> </Trigger> <!--<Trigger Property="IsMouseOver" Value="true"> <Setter Property="Background" TargetName="border" Value="{StaticResource Button.MouseOver.Background}"/> <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.MouseOver.Border}"/> </Trigger>--> <Trigger Property="IsPressed" Value="true"> <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Pressed.Background}"/> <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Pressed.Border}"/> </Trigger> <Trigger Property="IsEnabled" Value="false"> <Setter Property="Background" TargetName="border" Value="{StaticResource Button.Disabled.Background}"/> <Setter Property="BorderBrush" TargetName="border" Value="{StaticResource Button.Disabled.Border}"/> <Setter Property="TextElement.Foreground" TargetName="contentPresenter" Value="{StaticResource Button.Disabled.Foreground}"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <Button Width="380" Height="80" FontSize="30" FontFamily="VAG Rounded" Background="#337A05" Foreground="White" Margin="0,15" Content="BACK TO GAMES" Style="{StaticResource ButtonStyle1}"/> </Grid> </Window> 之后,您,中的逗号(payload)错过了。

sound: "default"

应该是:

const payload = {
        notification: {
            title: 'SahuSmaj : New Matrimony Post',
            body: `New biodata entered,check it out`,
            sound: "default"
            click_action: "MATRIMONY"
        }
    };