Hi All,
There is a requirement to integrate API to trigger a sms alert. I am using whisper to send sms
One member suggest me to use the following script to achieve this
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
username := "someuser"
password := "somepassword"
apiKey := "somekeyhere"
// build the URL
uri := fmt.Sprintf("https://api.whispir.com/messages?apikey=%s", apiKey)
// build the request structure
rawBody := struct {
To string `json:"to"`
Subject string `json:"subject"`
Body string `json:"body"`
}{
To: "+1000000000",
Subject: "Test SMS Message",
Body: "This is the body of my test SMS message",
}
// convert that structure into a JSON request
body, err := json.Marshal(rawBody)
if err != nil {
log.Fatal(err)
}
// build the POST the request with the headers set appropriately
req, err := http.NewRequest("POST", uri, bytes.NewReader(body))
req.Header.Add("Content-Type", "application/vnd.whispir.message-v1+json")
req.Header.Add("Accept", "application/vnd.whispir.message-v1+json")
req.SetBasicAuth(username, password)
// submit the request
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
// read the body of the results
content, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
// print the body of the results
fmt.Println(string(content))
}
My question is
What extension I should use to save this script. Is it .py ?
To the message can I include the node name and the ip address as follows ?
Body: "${N=SwisEntity;M=DisplayName} : ${N=SwisEntity;M=IP_Address} is Down",
SEND SMS using JSON
HTTP 1.1 POST https://api.whispir.com/messages?apikey=[your_key]
Authorization: Basic am9obi5zbWl0aDpteXBhc3N3b3Jk
Content-Type: application/vnd.whispir.message-v1+xml
Accept: application/vnd.whispir.message-v1+xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:messagexmlns:ns2="http://schemas.api.whispir.com">
<to>+1000000000</to>
<subject>Test SMS Message</subject>
<body>This is the body of my test SMS message</body>
</ns2:message>
Content-Type:application/vnd.whispir.message-v1+json
Accept:application/vnd.whispir.message-v1+json
{
"to":"+1000000000",
"subject":"Test SMS Message",
"body":"This is the body of my test SMS message"
}
Response: 202 Accepted
Location: https://api.whispir.com/messages/{id}?apikey=[your_key]