sendPushMessageToUsers method

  1. @override
Future<DataResult<NUIPushOSResponse>> sendPushMessageToUsers({
  1. required String title,
  2. String? subtitle,
  3. required String content,
  4. NUIEnt? data,
  5. List<String>? userIds,
  6. String? bigPictureUrl,
  7. String? channelId,
})
override

Send push notification to the targeted users

Implementation

@override
Future<DataResult<NUIPushOSResponse>> sendPushMessageToUsers({required String title, String? subtitle, required String content, NUIEnt? data, List<String>? userIds, String? bigPictureUrl, String? channelId}) async{
  try{
    logNUI(_MODULE, "Sending push notification to users : $userIds");
    final notification = NUIPushOSNotification(
      appId: _oneSignalAppId,
      headings: {"en": title},
      subtitle: subtitle != null ? {"en": subtitle} : null,
      contents: {"en": content},
      includePlayerIds: userIds ?? [],
      data: data?.toMap(),
      bigPicture: bigPictureUrl,
      huawei_big_picture: bigPictureUrl,
      android_channel_id: channelId,
      huawei_channel_id: channelId,
    );

    final result = await NUIWeb.get(module: _NUIWEB_ONESIGNAL).doPOST<NUIPushOSResponse>(
      url: '',
      bodyEnt: notification,
      headers: _oneSignalPushHeaders(),
      entity: NUIPushOSResponseEntity(),
    );

    if(result.success == true){
      logNUI(_MODULE, "Send push message to users successful");
      return DataResult(
          success: true,
          message: "Send push message to users successful",
          code: NUIPushCode.PUSH_TO_USERS_SUCCESS.name
      );
    }
    else{
      logNUI(_MODULE, "Failed to send push message to users with message: ${result.message}");
      return DataResult(
          success: false,
          message: "Failed to send push message to users with message : ${result.message}",
          code: NUIPushCode.PUSH_TO_USERS_FAILED.name
      );
    }
  }catch(e){
    logNUI(_MODULE, "Failed to send push message to users with error : $e");
    return DataResult(
        success: false,
        message: "Failed to send push message to users with error: $e",
        code: NUIPushCode.PUSH_TO_USERS_FAILED.name
    );
  }
}