Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Updated Twilio information to properly use accountSID and added a tes…
Browse files Browse the repository at this point in the history
…t flag to combine with sms to do testing
  • Loading branch information
ianmarmour committed Sep 21, 2020
1 parent 765a7ad commit c411231
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ set NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE
#### Additional SMS Configuration
```
set TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID_HERE
set TWILIO_SERVICE_SID=YOUR_TWILIO_SERVICE_SID_HERE
set TWILIO_TOKEN=YOUR_TWILIO_TOKEN_HERE
set TWILIO_SOURCE_NUMBER=YOUR_TWILIO_SERVICE_NUMBER_HERE
set TWILIO_DESTINATION_NUMBER=YOUR_DESITNATION_NUMBER_FOR_NOTIFICATIONS_HERE
Expand All @@ -66,7 +65,6 @@ export NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE
```
export NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE
export TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID_HERE
export TWILIO_SERVICE_SID=YOUR_TWILIO_SERVICE_SID_HERE
export TWILIO_TOKEN=YOUR_TWILIO_TOKEN_HERE
export TWILIO_SOURCE_NUMBER=YOUR_TWILIO_SERVICE_NUMBER_HERE
export TWILIO_DESTINATION_NUMBER=YOUR_DESITNATION_NUMBER_FOR_NOTIFICATIONS_HERE
Expand All @@ -85,7 +83,6 @@ export NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE
```
export NVIDIA_CLERK_SKU=YOUR_DESIRED_SKU_HERE
export TWILIO_ACCOUNT_SID=YOUR_TWILIO_ACCOUNT_SID_HERE
export TWILIO_SERVICE_SID=YOUR_TWILIO_SERVICE_SID_HERE
export TWILIO_TOKEN=YOUR_TWILIO_TOKEN_HERE
export TWILIO_SOURCE_NUMBER=YOUR_TWILIO_SERVICE_NUMBER_HERE
export TWILIO_DESTINATION_NUMBER=YOUR_DESITNATION_NUMBER_FOR_NOTIFICATIONS_HERE
Expand Down
2 changes: 1 addition & 1 deletion internal/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

//SendText Sends an SMS notification using Twilio Service.
func SendText(item string, config config.TwilioConfig, client *http.Client) error {
endpoint := fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages", config.ServiceSID)
endpoint := fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages", config.AccountSID)

msgData := url.Values{}
msgData.Set("To", config.DestinationNumber)
Expand Down
8 changes: 0 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

type TwilioConfig struct {
AccountSID string
ServiceSID string
Token string
SourceNumber string
DestinationNumber string
Expand All @@ -29,13 +28,6 @@ func GetTwilioConfig() TwilioConfig {

configuration.AccountSID = accountSid

serviceSid, serviceSidOk := os.LookupEnv("TWILIO_SERVICE_SID")
if serviceSidOk == false {
log.Fatal("TWILIO_SERVICE_SID Environment Variable is unset, exiting.")
}

configuration.ServiceSID = serviceSid

token, tokenOk := os.LookupEnv("TWILIO_TOKEN")
if tokenOk == false {
log.Fatal("TWILIO_TOKEN Environment Variable is unset, exiting.")
Expand Down
34 changes: 30 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,43 @@ import (
"github.com/ianmarmour/nvidia-clerk/internal/rest"
)

func main() {
browser.StartChromeDebugMode()
sessionContext := browser.StartSession()
func runTest(name string, client *http.Client, config config.Config) {
switch name {
case "sms":
textErr := alert.SendText(config.SKU, config.TwilioConfig, client)
if textErr != nil {
fmt.Printf("Error testing SMS notification exiting...\n")
os.Exit(1)
} else {
fmt.Printf("SMS Notification testing completed succesfully")
}
default:

}

fmt.Printf("Testing completed succesfully exiting...\n")
os.Exit(0)
}

func main() {
// Parse Argument Flags
useSms := flag.Bool("sms", false, "Enable SMS notifications for whenever SKU is in stock.")
useTest := flag.Bool("test", false, "Enable testing mode")
flag.Parse()

config := config.GetConfig(*useSms)

httpClient := &http.Client{Timeout: 10 * time.Second}

// Execute Tests
if *useTest == true {
if *useSms == true {
runTest("sms", httpClient, config)
}
}

browser.StartChromeDebugMode()
sessionContext := browser.StartSession()

for {
skuInfo, skuInfoErr := rest.GetSkuInfo(config.SKU, httpClient)
if skuInfoErr != nil {
Expand Down

0 comments on commit c411231

Please sign in to comment.