forked from dasrick/go-teams-notify
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use proxy for http client? #240
Labels
question
Further information is requested
Comments
atc0005
added
question
Further information is requested
help wanted
Extra attention is needed
labels
Oct 31, 2023
Hi @ahfa92, I've not tried that before, but I found what I think is a good explanation here: Here is an untested example based on the existing adaptivecard/basic example: package main
import (
"log"
"net/http"
"net/url"
"os"
goteamsnotify "github.com/atc0005/go-teams-notify/v2"
"github.com/atc0005/go-teams-notify/v2/adaptivecard"
)
func main() {
// Initialize a new Microsoft Teams client.
mstClient := goteamsnotify.NewTeamsClient()
proxyURLString := "http://proxyIp:proxyPort"
proxyUrl, err := url.Parse(proxyURLString)
if err != nil {
log.Printf(
"failed to parse proxy URL %q: %v",
proxyURLString,
err,
)
os.Exit(1)
}
httpClient := mstClient.HTTPClient()
httpClient.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
// Set webhook url.
webhookUrl := "https://outlook.office.com/webhook/YOUR_WEBHOOK_URL_OF_TEAMS_CHANNEL"
// The title for message (first TextBlock element).
msgTitle := "Hello world"
// Formatted message body.
msgText := "Here are some examples of formatted stuff like " +
"\n * this list itself \n * **bold** \n * *italic* \n * ***bolditalic***"
// Create message using provided formatted title and text.
msg, err := adaptivecard.NewSimpleMessage(msgText, msgTitle, true)
if err != nil {
log.Printf(
"failed to create message: %v",
err,
)
os.Exit(1)
}
// Send the message with default timeout/retry settings.
if err := mstClient.Send(webhookUrl, msg); err != nil {
log.Printf(
"failed to send message: %v",
err,
)
os.Exit(1)
}
} Feedback is welcome. |
I will try to use this method. Will inform you later. Thanks! |
The solution is working. Thank you!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can we use proxy server for this package?
In an environment which is very strict, we can not simply use http_proxy for global application. Is there any way to route the url via proxy server e.g. squid proxy?
Thank you in advance!!
The text was updated successfully, but these errors were encountered: