example_event.go 884 B

123456789101112131415161718192021222324252627282930313233343536
  1. package public
  2. import (
  3. "context"
  4. "github.com/open-dingtalk/dingtalk-stream-sdk-go/client"
  5. "github.com/open-dingtalk/dingtalk-stream-sdk-go/event"
  6. "github.com/open-dingtalk/dingtalk-stream-sdk-go/logger"
  7. "github.com/open-dingtalk/dingtalk-stream-sdk-go/utils"
  8. )
  9. /**
  10. * @Author linya.jj
  11. * @Date 2023/3/22 18:30
  12. */
  13. func RunEventListener(clientId, clientSecret string) {
  14. logger.SetLogger(logger.NewStdTestLogger())
  15. eventHandler := event.NewDefaultEventFrameHandler(event.EventHandlerDoNothing)
  16. cli := client.NewStreamClient(
  17. client.WithAppCredential(client.NewAppCredentialConfig(clientId, clientSecret)),
  18. client.WithUserAgent(client.NewDingtalkGoSDKUserAgent()),
  19. client.WithSubscription(utils.SubscriptionTypeKEvent, "*", eventHandler.OnEventReceived),
  20. )
  21. err := cli.Start(context.Background())
  22. if err != nil {
  23. panic(err)
  24. }
  25. defer cli.Close()
  26. select {}
  27. }