-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
sms_test.go | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//********************************************************** | ||
// | ||
// Copyright (C) 2018 - 2021 J&J Ideenschmiede UG (haftungsbeschränkt) <[email protected]> | ||
// | ||
// This file is part of placetel. | ||
// All code may be used. Feel free and maybe code something better. | ||
// | ||
// Author: Jonas Kwiedor | ||
// | ||
//********************************************************** | ||
|
||
package placetel | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// Send sms | ||
func SendSMS(recipient, message, token string) error { | ||
|
||
// Define client | ||
client := &http.Client{} | ||
|
||
// Set body | ||
body := strings.NewReader(`{"recipient": "` + recipient + `", "message": "` + message + `"}`) | ||
|
||
// Set request | ||
request, err := http.NewRequest("POST", "https://api.placetel.de/v2/sms", body) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Define header | ||
request.Header.Add("Content-Type", "application/json") | ||
request.Header.Add("Authorization", "Bearer "+token) | ||
|
||
// Send request to placetel | ||
response, err := client.Do(request) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Close response after function ends | ||
defer response.Body.Close() | ||
|
||
// Return | ||
return nil | ||
|
||
} |