示例#1
0
func main() {
	//exit if sessions with my username are found
	_, err := sh.Command("who").Command("grep", "my_username").Output()
	if err != nil {
		os.Exit(1)
	}

	//Grab Twilio ID and token from environment variables
	Account_Sid := os.Getenv("TWILIO_ACCOUNT_SID")
	Auth_Token := os.Getenv("TWILIO_AUTH_TOKEN")

	//create the reasons slice and append reasons to it
	reasons := make([]string, 0)
	reasons = append(reasons,
		"Locked out",
		"Pipes broke",
		"Food poisoning",
		"Not feeling well")

	// Initialize Twilio client and send message
	client := twilio.NewClient(Account_Sid, Auth_Token, nil)
	message := fmt.Sprint("Gonna work from home...", reasons[rand.Intn(len(reasons))])

	params := twilio.MessageParams{
		Body: message,
	}
	s, resp, err := client.Messages.Send(my_number, boss_number, params)

	if err == nil {
		log.Fatal(s, resp, err)
	}
}
示例#2
0
文件: voter.go 项目: rctl/Voter-Go
func sendSMS(c appengine.Context, to string, from string, message string) {
	client := urlfetch.Client(c)
	params := twilio.MessageParams{
		Body: message,
	}
	t := twilio.NewClient(AccountSid, AuthToken, client)
	s, resp, err := t.Messages.Send(from, to, params)
	c.Infof("Send:", s)
	c.Infof("Response:", resp)
	c.Infof("Err:", err)
}
示例#3
0
func main() {
	tc := twilio.NewClient(twilioAccount, twilioKey, nil)
	mc := mailgun.NewMailgun(emailDomain, mailgunKey, mailgunPublicKey)

	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Action(r.Handle)

	m.Map(tc)
	m.MapTo(mc, (*mailgun.Mailgun)(nil))

	r.Post("/call", verifyTwilioReq, incomingCall)
	r.Post("/record-voicemail", verifyTwilioReq, recordVoicemail)
	r.Post("/voicemail", verifyTwilioReq, incomingVoicemail)
	r.Post("/sms", verifyTwilioReq, incomingSMS)
	r.Post("/email", incomingEmail)
	r.Post("/hangup", hangup)
	r.Get("/ping", func() {})

	go pinger()
	m.Run()
}
示例#4
0
package twilhelp

import (
	"log"
	"os"

	"github.com/subosito/twilio"
)

var (
	TwilioAccount = os.Getenv("TWILIO_ACCOUNT")
	TwilioKey     = os.Getenv("TWILIO_KEY")
	FromNumber    = os.Getenv("FROM_NUMBER")

	tc = twilio.NewClient(TwilioAccount, TwilioKey, nil)
)

func init() {
	if TwilioAccount == "" {
		log.Println("TWILIO_ACCOUNT not set")
	}
	if TwilioKey == "" {
		log.Println("TWILIO_KEY not set")
	}
	if FromNumber == "" {
		log.Println("FROM_NUMBER not set")
	}

	if len(FromNumber) == 10 {
		FromNumber = "+1" + FromNumber
示例#5
0
文件: main.go 项目: elos/gaia
func main() {
	flag.Parse()

	var db data.DB
	var err error

	log.Printf("== Setting Up Database ==")
	log.Printf("\tDatabase Type: %s", *dbtype)
	switch *dbtype {
	case "mem":
		db = mem.NewDB()
	case "mongo":
		db, err = models.MongoDB(*dbaddr)
		if err != nil {
			log.Fatal(err)
		}
		log.Printf("\tConnected to mongo@%s", *dbaddr)
	default:
		log.Fatal("Unrecognized database type: '%s'", *dbtype)
	}
	log.Printf("== Set up Database ==")

	// DB CLIENT
	conn, err := grpc.Dial(":3334", grpc.WithInsecure())
	if err != nil {
		log.Fatalf("failed to dial: %v", err)
	}
	defer conn.Close()
	adbc := access.NewDBClient(conn)

	// AUTH CLIENT
	conn, err = grpc.Dial(":3333", grpc.WithInsecure())
	if err != nil {
		log.Fatalf("failed to dial: %v", err)
	}
	defer conn.Close()
	ac := auth.NewAuthClient(conn)

	// WEBUI SERVER
	lis, err := net.Listen("tcp", ":1113")
	if err != nil {
		log.Fatalf("failed to listen on :1113: %v", err)
	}
	g := grpc.NewServer()
	records.RegisterWebUIServer(g, records.Logged(records.NewWebUI(adbc, ac)))
	go g.Serve(lis)

	// WEB UI CLIENT
	conn, err = grpc.Dial(":1113", grpc.WithInsecure())
	if err != nil {
		log.Fatalf("failed to dial: %v", err)
	}
	defer conn.Close()
	webuiclient := records.NewWebUIClient(conn)

	// calendar WEBUI SERVER
	lis, err = net.Listen("tcp", ":1114")
	if err != nil {
		log.Fatalf("failed to listen on :1114: %v", err)
	}
	g = grpc.NewServer()
	cal.RegisterWebUIServer(g, cal.NewWebUI(adbc, ac))
	go g.Serve(lis)

	// cal WEB UI CLIENT
	conn, err = grpc.Dial(":1114", grpc.WithInsecure())
	if err != nil {
		log.Fatalf("failed to dial: %v", err)
	}
	defer conn.Close()
	calwebui := cal.NewWebUIClient(conn)

	if _, _, err := user.Create(db, "u", "p"); err != nil {
		log.Fatal("user.Create error: %s", err)
	}

	background := context.Background()

	log.Printf("== Connecting to Twilio ==")
	twilioClient := twilio.NewClient(TwilioAccountSid, TwilioAuthToken, nil)
	log.Printf("== Connected to Twilio ==")

	log.Printf("== Starting SMS Command Sessions ==")
	smsMux := services.NewSMSMux()
	go smsMux.Start(
		background,
		db,
		services.SMSFromTwilio(twilioClient, TwilioFromNumber),
	)
	log.Printf("== Started SMS Command Sessions ==")

	log.Printf("== Initiliazing Gaia Core ==")
	ga := gaia.New(
		context.Background(),
		new(gaia.Middleware),
		&gaia.Services{
			AppFileSystem:      http.Dir(*appdir),
			SMSCommandSessions: smsMux,
			DB:                 db,
			Logger:             services.NewLogger(os.Stderr),
			WebUIClient:        webuiclient,
			CalWebUIClient:     calwebui,
		},
	)
	log.Printf("== Initiliazed Gaia Core ==")

	log.Printf("== Starting Agents ===")
	user.Map(db, func(db data.DB, u *models.User) error {
		go agents.LocationAgent(background, db, u)
		go agents.TaskAgent(background, db, u)
		go agents.WebSensorsAgent(background, db, u)
		return nil
	})
	log.Printf("== Started Agents ===")

	log.Printf("== Starting HTTP Server ==")
	host := fmt.Sprintf("%s:%d", *addr, *port)
	log.Printf("\tServing on %s", host)
	if *certFile != "" && *keyFile != "" {
		if *port != 443 {
			log.Print("WARNING: serving HTTPS on a port that isn't 443")
		}

		if err = http.ListenAndServeTLS(host, *certFile, *keyFile, ga); err != nil {
			log.Fatal(err)
		}
	} else {
		log.Print("NOT SERVING SECURELY")
		if *port != 80 {
			log.Print("WARNING: serving HTTP on a port that isn't 80")
		}
		if err = http.ListenAndServe(host, ga); err != nil {
			log.Fatal(err)
		}
	}
	log.Printf("== Started HTTP Server ==")
}
示例#6
0
func main() {
	conf, err := loadConfig("config.json")
	if err != nil {
		fmt.Println("Error loading config!")
		fmt.Println(err)
		return
	}
	configuration = conf

	p.RegisterKey(configuration.ProwlKey)

	two = twilio.NewClient(configuration.TwilioSID, configuration.TwilioAuthToken, nil)
	if two == nil {
		fmt.Println("Couldn't set up Twilio")
		return
	}

	amzses.Init(configuration.AWSAccessKey, configuration.AWSSecretKey)
	fmt.Println("Configured SES")

	db, err = database.Connect(configuration.MongoURL)
	if err != nil {
		fmt.Println("Couldn't connect to Mongo database")
		fmt.Println(err)
		return
	}
	fmt.Println("Connected to MongoDB")

	cheers := time.NewTicker(10 * time.Minute)
	scrapeInfo := time.NewTicker(2 * time.Minute)
	go func() {
		for {
			select {
			case <-cheers.C:
				events, err := db.GetEventsForCurrentWeek()
				if err != nil {
					sendProwl("Time Error", "Couldn't get current events when sending Cheers", err)
					break
				}
				for _, e := range events {
					sendCheersForEvent(e)
				}
			case <-scrapeInfo.C:
				events, err := db.GetEventsForCurrentWeek()
				if err != nil {
					sendProwl("Time Error", "Couldn't get current events when scraping event info", err)
					break
				}
				for _, e := range events {
					if !e.AlliancesSent {
						sendAlliancesForEvent(e)
					}
					sendAwardsForEvent(e)
				}
			}
		}
	}()

	stream := make(chan []byte, 1000)
	done := make(chan bool)

	httpstream.OauthCon = oauth.NewConsumer(
		configuration.ConsumerKey,
		configuration.ConsumerSecret,
		oauth.ServiceProvider{
			RequestTokenUrl:   "http://api.twitter.com/oauth/request_token",
			AuthorizeTokenUrl: "https://api.twitter.com/oauth/authorize",
			AccessTokenUrl:    "https://api.twitter.com/oauth/access_token",
		})

	at := oauth.AccessToken{
		Token:  configuration.OAuthToken,
		Secret: configuration.OAuthSecret,
	}
	client := httpstream.NewOAuthClient(&at, httpstream.OnlyTweetsFilter(func(line []byte) {
		stream <- line
	}))
	fmt.Println("Connected to Twitter!")

	err = client.User(done)
	if err != nil {
		sendProwl("Error Starting Megaphone", "Couldn't start stream!", err)
		return
	}

	sendProwl("Started!", "Megaphone is running", nil)

	go func() {
		for line := range stream {
			handleLine(line)
		}
	}()
	_ = <-done
}