Пример #1
0
func main() {

	accountSid := "ACda22d76d1f0ca22dae6d9d8cff1307f6"
	authToken := "ca1704c1b5df5cdf98b564574edc69c9"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+14177202086"
	to := "+14179880783"

	// Seed the rng
	rand.Seed(time.Now().UTC().UnixNano())

	fmt.Println("Welcome to the mega SHA512 cracker!  Let's do this thing!!")
	fmt.Println("")
	fmt.Println("")

	for {
		num := strconv.FormatInt(rand.Int63n(1800000000000000000), 10)
		h := doHash(num)
		count := countLeadingZeros(h)
		if count >= 9 {
			fmt.Printf("\nCOUNT OF %d, Source: %s\n", count, num)
			fmt.Println(h)
			twilio.SendSMS(from, to, "Got a "+strconv.FormatInt(int64(count), 10)+": "+num, "", "")
		}
	}
}
Пример #2
0
func main() {
	accountSid := ""
	authToken := ""
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+"
	to := "+"
	message := "Hello World!"
	twilio.SendSMS(from, to, message, "", "")
}
Пример #3
0
func twilio() {
	accountSid := ""
	authToken := ""
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+1"
	to := "+1"
	message := "user connected!"
	twilio.SendSMS(from, to, message, "", "")
}
Пример #4
0
func main() {
	accountSid := ""
	authToken := ""
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+"
	to := "+"
	callbackParams := gotwilio.NewCallbackParameters("http://example.com")
	twilio.CallWithUrlCallbacks(from, to, callbackParams)
}
Пример #5
0
func twilio(tos string) {
	accountSid := ""
	authToken := ""
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+"
	to := "+1" + tos
	message := "Hello World!"
	twilio.SendSMS(from, to, message, "", "")
}
Пример #6
0
func (_ Test) sms() {
	accountSid := "ABC123..........ABC123"
	authToken := "ABC123..........ABC123"
	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	from := "+15555555555"
	to := "+15555555555"
	message := "Welcome to gotwilio!"
	twilio.SendSMS(from, to, message, "", "")
}
Пример #7
0
// SendSms provides the implementation of the SmsSender type for runtime usage.
func SendSms(smsNumber string, message string) error {
	twilio := gotwilio.NewTwilioClient(config.Settings.Twilio.AccountSid, config.Settings.Twilio.AuthToken)
	from := config.Settings.Twilio.Number

	_, exc, err := twilio.SendSMS(from, smsNumber, message, "", "")
	if err != nil {
		return err
	} else if exc != nil {
		return errors.New(exc.Message)
	}
	return nil
}
Пример #8
0
func (u *UpUser) SendVerifyCode(ph_area string, ph_num string) string {
	r := rand.New(rand.NewSource(time.Now().UnixNano()))
	rnum := string(r.Int31())[:5]
	log.Printf(rnum)
	conn := pool.Get()
	defer conn.Close()

	message := "Your verification code for JSONUp is " + rnum
	twilio := gotwilio.NewTwilioClient(*accountSid, *authToken)
	twilio.SendSMS("+61421812892", "+"+ph_area+ph_num, message, "", "")

	return rnum
}
Пример #9
0
func SendSMS(msg string) {
	if config.Params.Twilio.AccountSid == "" || config.Params.Twilio.AuthToken == "" {
		log.Println("twilio creds not set")
		return
	}

	twilio := gotwilio.NewTwilioClient(config.Params.Twilio.AccountSid, config.Params.Twilio.AuthToken)

	from := config.Params.Twilio.Number

	for i := 0; i < len(config.Params.Notify.Phones); i++ {
		twilio.SendSMS(from, config.Params.Notify.Phones[i], msg, "", "")
	}
}
Пример #10
0
func sendTwilio(message string) {
	defer func() {
		if err := recover(); err != nil {
			log.Printf("sendTwilio error: %v", err)
		}
	}()
	if len(message) > 50 {
		message = message[:50]
	}
	twilio := gotwilio.NewTwilioClient(twilioSid, twilioToken)
	res, exp, err := twilio.SendSMS(twilioFrom, twilioTo, message, "", "")
	if exp != nil || err != nil {
		log.Printf("sendTwilio error: %v %v %v", res, exp, err)
	}
}
Пример #11
0
func sendTwilio(message string) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("sendTwilio error", "error", err)
		}
	}()
	if len(message) > 50 {
		message = message[:50]
	}
	twilio := gotwilio.NewTwilioClient(config.GetString("alert_twilio_sid"), config.GetString("alert_twilio_token"))
	res, exp, err := twilio.SendSMS(config.GetString("alert_twilio_from"), config.GetString("alert_twilio_to"), message, "", "")
	if exp != nil || err != nil {
		log.Error("sendTwilio error", "res", res, "exp", exp, "error", err)
	}
}
Пример #12
0
func callDevTeam() {
	config := common.GetConfig()
	twilio := gotwilio.NewTwilioClient(config.TwilioSID, config.TwilioAuthToken)
	messageURL := "http://twimlets.com/message?Message%5B0%5D=SITE%20IS%20DOWN!"
	callbackParams := gotwilio.NewCallbackParameters(messageURL)

	for _, num := range config.Phones {
		fmt.Printf("!!! Calling %s\n", num)

		_, tException, err := twilio.CallWithUrlCallbacks(config.TwilioCallFrom, num, callbackParams)
		if tException != nil {
			panic(fmt.Sprintf("Twilio error: %+v\n", tException))
		}
		check(err)
	}
}
Пример #13
0
func (t *Twilio) KnockKnock(d *doorbot.Door, p *doorbot.Person) error {
	log.WithFields(log.Fields{
		"account_id":          t.Account.ID,
		"person_id":           p.ID,
		"person_phone_number": p.PhoneNumber,
		"door_id":             d.ID,
	}).Info("Notificator::Twilio->KnockKnock request")

	from := t.PhoneNumber
	to := p.PhoneNumber

	renderingData := map[string]string{
		"name": p.Name,
		"door": d.Name,
	}

	dbb := rendering.DoorbotBar()

	template := *t.Account.NotificationsSMSMessageTemplate
	if len(template) == 0 {
		template = "Hi {{name}}, there is someone waiting for your at the {{door}}."
	}

	message := dbb.Render(template, renderingData)

	twilio := gotwilio.NewTwilioClient(t.AccountSID, t.Token)
	// was response
	_, exception, err := twilio.SendSMS(from, to, message, "", "")
	if exception != nil {
		log.WithFields(log.Fields{
			"twilio_message": exception.Message,
			"twilio_code":    exception.Code,
			"account_id":     t.Account.ID,
			"person_id":      p.ID,
			"door_id":        d.ID,
			"sms_to":         to,
			"sms_from":       from,
		}).Error("Notificator::Twilio->KnockKnock twilio exception")

		return err
	}

	return nil
}
Пример #14
0
func main() {
	var err error
	db, err = sql.Open("sqlite3", "database.db")
	if err != nil {
		log.Println("Could not open DB")
		return
	}

	// Twilio Config
	from = "+14847184408"
	accountSid := "AC800a64542126d28255c7c82aa375627f"
	authToken := "f8c3c917be8b7ec2225a6066eff08719"
	twilio = gotwilio.NewTwilioClient(accountSid, authToken)

	r := mux.NewRouter()

	// User authentication, registration and management
	r.HandleFunc("/users/register", RegisterUserHandler).Methods("POST")
	r.HandleFunc("/users/login", LoginUserHandler).Methods("POST")
	r.HandleFunc("/users/info", restrict.R(InfoHandler)).Methods("GET")

	// Food graph handling
	r.HandleFunc("/foods/graph", FoodGraphHandler).Methods("GET")

	// Pantry management
	r.HandleFunc("/pantry", restrict.R(RegisterFoodHandler)).Methods("POST")
	r.HandleFunc("/pantry", restrict.R(AllFoodInPantryHandler)).Methods("GET")
	r.HandleFunc("/pantry/consume", restrict.R(ConsumeFoodHandler)).Methods("POST")

	r.HandleFunc("/pantry/queue", restrict.R(AddItemToQueueHandler)).Methods("POST")
	r.HandleFunc("/pantry/mass_change", restrict.R(MassChangeHandler)).Methods("POST")
	r.HandleFunc("/pantry/remove_poll", restrict.R(RemovePollHandler)).Methods("GET")

	http.Handle("/", r)

	log.Fatal(http.ListenAndServe(":8080", nil))
}
Пример #15
0
// Init initializes the givegn TwilioOutput instance by
//extracting from, to, sid and token value from config
//and store it on the plugin instance.
func (o *TwilioOutput) Init(config interface{}) error {
	conf := config.(*TwilioOutputConfig)
	o.From, o.To = conf.From, conf.To
	o.client = gotwilio.NewTwilioClient(conf.Sid, conf.Token)
	return nil
}
Пример #16
0
func (c *SmsController) SmsRouter(Body string, From string, AccountSid string) revel.Result {
	accountSid := os.Getenv("TWILIO_ACCOUNT_SID")
	authToken := os.Getenv("TWILIO_AUTH_TOKEN")
	responderPhone := os.Getenv("TWILIO_FROM_NUMBER")

	errJson := make(jsn)

	if accountSid == "" || authToken == "" || responderPhone == "" {
		if AccountSid != accountSid {
			message := "Twilio cannot be used before setting up the environment!"
			revel.ERROR.Print(message)
			errJson.SetError(message)
			c.Response.Status = 500
			return c.RenderJson(errJson)
		}
	}

	if AccountSid != accountSid {
		revel.ERROR.Print("Got a text from Twilio with incorrect account")
		c.Response.Status = 400
		errJson.SetError("Not Authorized")
		return c.RenderJson(errJson)
	}

	twilio := gotwilio.NewTwilioClient(accountSid, authToken)

	if AccountSid != accountSid {
		message := "Twilio not authorized"
		revel.ERROR.Print(message)
		errJson.SetError(message)
		c.Response.Status = 400
		return c.RenderJson(errJson)
	}

	phone, err := utils.NormalizePhoneToE164(From)
	if err != nil {
		message := "Invalid phone number. Phone number must be passed as a string in E.164 format"
		revel.ERROR.Print(message)
		errJson.SetError(message)
		c.Response.Status = 400
		return c.RenderJson(errJson)
	}

	textingUser, err := models.UserFromPhone(phone)
	if err != nil {
		message := "No user is registered with this phone number. Please sign up with your phone number online and try again."
		revel.ERROR.Print(message, " from: ", phone)
		errJson.SetError(message)
		twilio.SendSMS(responderPhone, phone, message, "", "")
		c.Response.Status = 422
		return c.RenderJson(errJson)
	}

	// Do the actual dispatching to different handlers
	lowerTrimmedBody := strings.ToLower(strings.TrimSpace(Body))
	var (
		smsText    string
		statusCode int
		jsnObject  map[string]string
	)
	switch {
	case strings.Contains(lowerTrimmedBody, "stats"):
		// call stats
	default: // attempting a tag via text
		smsText, statusCode, jsnObject = TagByPhone(lowerTrimmedBody, textingUser)
	}

	twilio.SendSMS(responderPhone, phone, smsText, "", "")
	c.Response.Status = statusCode
	return c.RenderJson(jsnObject)
}
Пример #17
0
func alertInit() {
	alertFuncs = make(map[string]AlertFunc)

	alertFuncs["email"] = func(data string, check *Check, result *CheckResult, db *sql.DB) error {
		subject := fmt.Sprintf("Check %s: %s", result.Status, check.Name)

		var body string
		if result.Status == StatusOnline {
			body = fmt.Sprintf("Check [%s] is now online.", check.Name)
		} else {
			body = fmt.Sprintf("Check [%s] is now %s: %s", check.Name, result.Status, result.Message)
		}
		body += fmt.Sprintf("\n\nID: %d\nName: %s\nType: %s\nData: %s\n\ngobearmon", check.Id, check.Name, check.Type, check.Data)
		return mail(subject, body, data)
	}

	alertFuncs["http"] = func(data string, check *Check, result *CheckResult, db *sql.DB) error {
		resp, err := http.PostForm(data, url.Values{
			"check_id": {strconv.Itoa(int(check.Id))},
			"name":     {check.Name},
			"type":     {check.Type},
			"data":     {check.Data},
			"status":   {string(result.Status)},
			"message":  {result.Message},
		})
		if err != nil {
			return err
		}
		resp.Body.Close()
		return nil
	}

	alertFuncs["sms"] = func(data string, check *Check, result *CheckResult, db *sql.DB) error {
		var message string
		if result.Status == StatusOnline {
			message = fmt.Sprintf("Check [%s] is now online.", check.Name)
		} else {
			message = fmt.Sprintf("Check [%s] is now %s: %s", check.Name, result.Status, result.Message)
		}
		twilio := gotwilio.NewTwilioClient(cfg.Twilio.AccountSid, cfg.Twilio.AuthToken)
		resp, exception, err := twilio.SendSMS(cfg.Twilio.From, data, message, "", "")
		if err != nil {
			return err
		} else if exception != nil {
			return fmt.Errorf("error(%d/%d): %s (%s)", exception.Status, exception.Code, exception.Message, exception.MoreInfo)
		}
		db.Exec("INSERT INTO charges (check_id, type, data) VALUES (?, ?, ?)", check.Id, "sms", resp.Sid)
		return nil
	}

	alertFuncs["voice"] = func(data string, check *Check, result *CheckResult, db *sql.DB) error {
		message := fmt.Sprintf("This is a monitoring-related call from go bear mon . The check . %s . has been recorded . %s . Reason is . %s", check.Name, result.Status, result.Message)
		twilio := gotwilio.NewTwilioClient(cfg.Twilio.AccountSid, cfg.Twilio.AuthToken)
		params := gotwilio.NewCallbackParameters("http://twimlets.com/message?Message=" + url.QueryEscape(message))
		resp, exception, err := twilio.CallWithUrlCallbacks(cfg.Twilio.From, data, params)
		if err != nil {
			return err
		} else if exception != nil {
			return fmt.Errorf("error(%d/%d): %s (%s)", exception.Status, exception.Code, exception.Message, exception.MoreInfo)
		}
		db.Exec("INSERT INTO charges (check_id, type, data) VALUES (?, ?, ?)", check.Id, "voice", resp.Sid)
		return nil
	}
}