Esempio n. 1
0
func NewTwilio(accountSid, authToken, from, to string) *Twilio {
	twilioClient := twilio.NewClient(accountSid, authToken)

	return &Twilio{
		client: twilioClient,
		from:   from,
		to:     to,
	}
}
func main() {
	sleepTime := time.Millisecond * 5000 // 5 seconds
	receiveMessageNum := 10
	fmt.Println("===========================================")
	fmt.Println(fmt.Sprintf(" Use CPU(s) num      : %d", runtime.NumCPU()))
	fmt.Println(fmt.Sprintf(" Receive message num : %d", receiveMessageNum))
	fmt.Println(fmt.Sprintf(" Sleep time          : 5 second(s)"))
	fmt.Println("===========================================")

	runtime.GOMAXPROCS(runtime.NumCPU())
	auth := aws.Auth{AccessKey: amazonAccessKey, SecretKey: amazonSecretKey}
	mySqs := sqs.New(auth, aws.EUWest)
	queue := &sqs.Queue{mySqs, amazonQueueName}
	client := twilio.NewClient(twilioSid, twilioAt)
	worker_sms.Start(queue, worker_sms.HandlerFunc(Print), sleepTime, receiveMessageNum, client, twilioSender)
}
Esempio n. 3
0
//Init read yaml config
func (sender *Sender) Init(senderSettings map[string]string, logger *logging.Logger) error {
	apiType := senderSettings["type"]

	apiASID := senderSettings["api_asid"]
	if apiASID == "" {
		return fmt.Errorf("Can not read [%s] api_sid param from config", apiType)
	}

	apiAuthToken := senderSettings["api_authtoken"]
	if apiAuthToken == "" {
		return fmt.Errorf("Can not read [%s] api_authtoken param from config", apiType)
	}

	apiFromPhone := senderSettings["api_fromphone"]
	if apiFromPhone == "" {
		return fmt.Errorf("Can not read [%s] api_fromphone param from config", apiType)
	}

	twilioClient := twilio.NewClient(apiASID, apiAuthToken)

	switch apiType {
	case "twilio sms":
		sender.sender = &twilioSenderSms{twilioSender{twilioClient, apiFromPhone, logger}}

	case "twilio voice":
		voiceURL := senderSettings["voiceurl"]
		if voiceURL == "" {
			return fmt.Errorf("Can not read [%s] voiceurl param from config", apiType)
		}

		sender.sender = &twilioSenderVoice{twilioSender{twilioClient, apiFromPhone, logger}, voiceURL}

	default:
		return fmt.Errorf("Wrong twilio type: %s", apiType)
	}

	return nil
}
Esempio n. 4
0
func NewTwilioNotification(sid, token, from string, recipients []string) *TwilioNotification {
	return &TwilioNotification{sid, token, from, recipients, twilio.NewClient(sid, token)}
}