GoogleScript.gs - OneSignal create notification.

📋
function doGet(e){
    handleFunction(e);
  }
function doPost(e){
    handleFunction(e);
  }
function handleFunction(request){
    RunningS(request);
  }
function RunningS(request){
    try {
        var appID = request.parameter.appID;
        var title = request.parameter.title;
        var body = request.parameter.body;
        var RESTAPIKey =request.parameter.RESTAPIKey;
        var url = "https://onesignal.com/api/v1/notifications";
        var D = {app_id:appID, included_segments:["All"],
        headings:{"en" : title},
        contents: {"en" : body},
        data: {"type":  "phoneNumber"}
        };
        
        var payload = JSON.stringify(D);
        var headers = { "Accept":"application/json", "Content-Type":"application/json", "Authorization":"Basic "+RESTAPIKey};
        var options = { "method":"POST","headers": headers,"payload" : payload};
        var response = UrlFetchApp.fetch(url, options);
        }
    catch (error) {
        throw new Error('É crucial digitar todos os dados corretamente, essa menssagem informa isto! [ TENTE NOVAMENTE ]') ;
    }
  }



📋
<div class="diving">
<input class="putting" placeholder="OneSignal AppID" type="text" id="OneSignalAppID"><br>
<input class="putting" placeholder="Basic RESTAPIKey" type="text" id="RESTAPIKey"><br><br>

<input class="putting" placeholder="Titulo da messagem" type="text" id="title"><br>
<input class="putting" placeholder="Corpo da menssagem" type="text" id="body"><br>

<input type="submit" onclick="FirstActivity(OneSignalAppID.value, RESTAPIKey.value, title.value, body.value)" value="Enviar Notificação"><br><br>


</div>



📋

<script>
function FirstActivity(value) {
var APPID = document.getElementById('OneSignalAppID').value;
var TITLE = document.getElementById('title').value;
var BODY = document.getElementById('body').value;
var API = document.getElementById('RESTAPIKey').value;

if(APPID.length == 0 || TITLE.length == 0 || BODY.length == 0 || API.length == 0){
}else{
   document.location.href = "https://script.google.com/macros/s/AKfycby7zDCc-vi4F3jPL5r0S01fGCt3JzUGaMpHQa_IL-r8AF2ghLg5/exec?appID="+APPID+"&title="+TITLE+"&body="+BODY+"&RESTAPIKey="+API;
}

}

</script>











Nenhum comentário:

Postar um comentário

Obrigado por comentar, volte sempre!

Seguidores

Pages




Ajude continuar nossos projetos.    

Copie este código: [[address]]

Donation of [[value]] BTC Received. Thank You.
[[error]]






Copiado