get_automation_logic.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package whatsapp
  2. import (
  3. "context"
  4. "wechat-api/hook/aliyun"
  5. "wechat-api/internal/svc"
  6. "wechat-api/internal/types"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. type GetAutomationLogic struct {
  10. logx.Logger
  11. ctx context.Context
  12. svcCtx *svc.ServiceContext
  13. }
  14. func NewGetAutomationLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAutomationLogic {
  15. return &GetAutomationLogic{
  16. Logger: logx.WithContext(ctx),
  17. ctx: ctx,
  18. svcCtx: svcCtx}
  19. }
  20. func (l *GetAutomationLogic) GetAutomation(req *types.AutomationReq) (*types.AutomationResp, error) {
  21. resp := types.AutomationResp{}
  22. automation, err := aliyun.GetAutomation(*req.WaId, *req.Phone)
  23. l.Logger.Infof("automation=%v err=%v\n", automation, err)
  24. if err != nil {
  25. resp.Msg = err.Error()
  26. resp.Code = 1
  27. }
  28. // 获取内容并赋值
  29. if automation.Body.Data.Commands != nil {
  30. for _, v := range automation.Body.Data.Commands {
  31. resp.Data.Commands = append(resp.Data.Commands, types.Command{
  32. CommandDescription: *v.CommandDescription,
  33. CommandName: *v.CommandName,
  34. })
  35. }
  36. }
  37. if automation.Body.Data.Prompts != nil {
  38. for _, v := range automation.Body.Data.Prompts {
  39. resp.Data.Prompts = append(resp.Data.Prompts, *v)
  40. }
  41. }
  42. if automation.Body.Data.PhoneNumber != nil {
  43. resp.Data.Phone = *automation.Body.Data.PhoneNumber
  44. }
  45. if automation.Body.Data.EnableWelcomeMessage != nil {
  46. resp.Data.EnableWelcomeMessage = *automation.Body.Data.EnableWelcomeMessage
  47. }
  48. return &resp, nil
  49. }