tasks

package
v1.35.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SendUserEmail = delay.Func("referrer-send-user-email", func(ctx context.Context, orgId string, templateName string, usrId string) {
	db := datastore.New(ctx)
	org := organization.New(db)
	if err := org.GetById(orgId); err != nil {
		log.Error("Could not get organization '%s', %s", orgId, err, ctx)
		return
	}

	if !org.Email.Enabled {
		return
	}

	nsCtx := org.Namespaced(ctx)
	nsDb := datastore.New(nsCtx)
	usr := user.New(nsDb)
	if err := usr.GetById(usrId); err != nil {
		log.Error("Could not get user '%s'", usrId, ctx)
		return
	}

})

Fire webhooks

View Source
var SendWoopraEvent = delay.Func("referrer-send-woopra-event", func(ctx context.Context, orgId, domain, usrId, id, kind string) {
	db := datastore.New(ctx)
	org := organization.New(db)

	if err := org.GetById(orgId); err != nil {
		log.Error("Could not get organization '%s', %s", orgId, err, ctx)
		return
	}

	nsCtx := org.Namespaced(ctx)
	nsDb := datastore.New(nsCtx)
	usr := user.New(nsDb)
	if err := usr.GetById(usrId); err != nil {
		log.Panic("Could not get referring user '%s'", usrId, ctx)
		return
	}

	if err := usr.LoadReferrals(); err != nil {
		log.Panic("Could not load referring user's referrals '%s'", usrId, ctx)
		return
	}

	usrId2 := ""
	orderId := ""
	orderNumber := ""

	switch kind {
	case "order":
		log.Debug("Loading order referrent")
		ord := order.New(nsDb)
		orderId = id
		if err := ord.GetById(id); err != nil {
			log.Panic("Could not get referrent user '%s'", usrId, ctx)
			return
		}
		usrId2 = ord.UserId
		orderNumber = strconv.Itoa(ord.Number)
	case "user":
		log.Debug("Loading user referrent")
		usrId2 = id
	default:
		log.Panic("unknown kind %s", kind, ctx)
		return
	}

	usr2 := user.New(nsDb)
	if err := usr2.GetById(usrId2); err != nil {
		log.Panic("Could not get referrent user '%s'", usrId, ctx)
		return
	}

	wt, _ := woopra.NewTracker(map[string]string{

		"host": domain,

		"timeout": "30000",
	})

	revokedReferrals := 0
	for _, v := range usr.Referrals {
		if v.Revoked {
			revokedReferrals += 1
		}
	}

	values := make(map[string]string)
	values["first_name"] = usr.FirstName
	values["last_name"] = usr.LastName
	values["city"] = usr.ShippingAddress.City
	values["country"] = usr.ShippingAddress.Country
	values["referred_by"] = usr.ReferrerId
	values["referrals"] = strconv.Itoa(len(usr.Referrals))
	values["active_referrals"] = strconv.Itoa(len(usr.Referrals) - revokedReferrals)
	values["revoked_referrals"] = strconv.Itoa(revokedReferrals)

	person := woopra.Person{
		Id:     usr.Id(),
		Name:   usr.Name(),
		Email:  usr.Email,
		Values: values,
	}

	ident := wt.Identify(
		ctx,
		person,
		"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7 (KHTML, like Gecko) Version/9.1.2 Safari/601.7.7",
	)

	ident.Track(
		"New Referral",
		map[string]string{
			"referred_id":           usr2.Id(),
			"referred_name":         usr2.Name(),
			"referred_email":        usr2.Email,
			"referred_order_id":     orderId,
			"referred_order_number": orderNumber,
		})

	ident.Push()
})

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL