-
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.
feat: auto add line bot after line oauth consent
- Loading branch information
Showing
3 changed files
with
68 additions
and
21 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
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
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,52 @@ | ||
package line_utils | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
type FriendshipStatusResponse struct { | ||
FriendFlag bool `json:"friendFlag"` | ||
} | ||
|
||
func GetFriendshipStatus(accessToken string) (friendFlag bool, err error) { | ||
// Define the API endpoint | ||
url := "https://api.line.me/friendship/v1/status" | ||
|
||
// Create a new HTTP client | ||
client := &http.Client{} | ||
|
||
// Create the request | ||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
// Add the Authorization header | ||
req.Header.Add("Authorization", "Bearer "+accessToken) | ||
|
||
// Perform the request | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return false, err | ||
} | ||
defer func(Body io.ReadCloser) { | ||
_ = Body.Close() | ||
}(resp.Body) | ||
|
||
// Read the response body | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
// Unmarshal the JSON response | ||
var response FriendshipStatusResponse | ||
err = json.Unmarshal(body, &response) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return response.FriendFlag, nil | ||
} |