Ejemplo n.º 1
0
func main() {

	// Set up a connection to the server.
	conn, err := grpc.Dial(address, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
	c := pb.NewNotificationServiceClient(conn)
	ctx, _ := context.WithTimeout(context.Background(), time.Second*5)
	sr, _ := c.Scan(context.Background(), &pb.ScanRequest{})
	log.Printf("Scan %v:", sr.Events)
	for _, e := range sr.Events {
		log.Println(e.Name)
		for _, t := range e.Templates {
			log.Printf("%s: %s = %v", e.Name, t.Suffix, t.Languages)
		}
	}

	message := &pb.Message{
		Event:    "verify-email",
		Language: "en",
		Tags:     map[string]string{"user_id": "b5980760-dc0b-4ed9-9aa5-489c85c5fa5e"},
		DataJson: pb.Map2Str(map[string]interface{}{
			"name":  "Sercan",
			"count": 1}),
		Targets: pb.NewTargets(
			/*			&pb.Email{
						ToEmail: []string{"*****@*****.**"},
						Cc:      []string{"*****@*****.**"},
					},*/
			&pb.Push{
				Template: []byte(`Selam {{.name}} fella`),
			}),
	}
	r, err := c.SendMessage(ctx, message)
	if err != nil {
		log.Fatalf("could not send message: %v", err)
	}
	log.Printf("Result: %s\n%d", r.Output, len(r.Results))
	for _, r2 := range r.Results {
		log.Printf("[%s]: %s", r2.Target, r2.Output)
	}
}
Ejemplo n.º 2
0
func main() {

	// Set up a connection to the server.
	conn, err := grpc.Dial(address, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	defer conn.Close()
	c := pb.NewNotificationServiceClient(conn)

	message := &pb.Message{
		Template: "welcome",
		//Language: "en",
		Targets: []*pb.Target{
			pb.NewEmailTarget(&pb.Email{
				ToEmail: []string{"*****@*****.**"},
				Cc:      []string{"*****@*****.**"},
				Data:    map[string]string{"name": "sercan"},
			}),
			/*pb.NewSmsTarget(&pb.Sms{
				To: []string{"+21123124", "+123124"},
			}),
			pb.NewPushTarget(&pb.Push{
				To: []string{"asdaf78a6sfa6f5asf", "j1g24feqfwd7as6d6t7asf"},
			}),*/
		},
	}

	r, err := c.SendMessage(context.Background(), message)

	if err != nil {
		log.Fatalf("could not send message: %v", err)
	}

	log.Printf("Result: %d\n%s\n%d", r.Type, r.Data, len(r.Results))
	for _, r2 := range r.Results {
		log.Printf("[%s]='%s': %d-%s", r2.Target, r2.Driver, r2.Type, r2.Data)
	}
}