boweniac 1 周之前
父节点
当前提交
05d07e8cf4
共有 2 个文件被更改,包括 5 次插入5 次删除
  1. 4 4
      crontask/contact_form.go
  2. 1 1
      crontask/init.go

+ 4 - 4
crontask/contact_form.go

@@ -191,7 +191,7 @@ func openaiRequest(messages string, template []custom_types.ContactFieldTemplate
 		"chat_history": messages,
 		"external_id":  uuid.New().String(),
 	}
-	logx.Infof("bodyData: %+v", bodyData)
+	logx.Info("bodyData: %+v", bodyData)
 	bodyBytes, err := json.Marshal(bodyData)
 	if err != nil {
 		return nil, err
@@ -330,7 +330,7 @@ func (l *CronTask) UpdateContactFields(botID string, receiverID string, fields [
 		} else {
 			f, _ := l.svcCtx.DB.ContactField.Query().Where(contactfield.ContactID(c.ID), contactfield.FormID(field.DataIndex)).First(l.ctx)
 			if f == nil {
-				if field.Value != nil && len(field.Value) > 0 {
+				if field.Value != nil && len(field.Value) > 0 && field.Value[0] != "" {
 					_, err := l.svcCtx.DB.ContactField.Create().
 						SetContactID(c.ID).
 						SetFormID(field.DataIndex).
@@ -342,8 +342,8 @@ func (l *CronTask) UpdateContactFields(botID string, receiverID string, fields [
 				}
 			} else {
 				if field.Value != nil {
-					if len(field.Value) == 0 {
-						field.Value = []string{""}
+					if len(field.Value) == 0 || field.Value[0] == "" {
+						continue
 					}
 					_, err := l.svcCtx.DB.ContactField.UpdateOneID(f.ID).
 						SetValue(field.Value).

+ 1 - 1
crontask/init.go

@@ -49,7 +49,7 @@ func ScheduleRun(c *cron.Cron, serverCtx *svc.ServiceContext) {
 	})
 
 	contactForm := NewCronTask(context.Background(), serverCtx)
-	c.AddFunc("1 0 * * *", func() {
+	c.AddFunc("*/5 * * * *", func() {
 		contactForm.analyze()
 	})
 }