Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkinStars committed Oct 16, 2024
2 parents 9413b7d + 86579a0 commit 2d97fc5
Show file tree
Hide file tree
Showing 67 changed files with 4,846 additions and 564 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ The Connector plugin helps us to implement third-party login functionality. For

The Storage plugin helps us to upload files to third-party storage. For example: Aliyun OSS or AWS S3.

- [x] [Aliyun](https://github.com/apache/incubator-answer-plugins/tree/main/storage-aliyunoss)
- [x] [Aliyun OSS](https://github.com/apache/incubator-answer-plugins/tree/main/storage-aliyunoss)
- [x] [Tencentyun COS](https://github.com/apache/incubator-answer-plugins/tree/main/storage-tencentyuncos)
- [x] [S3](https://github.com/apache/incubator-answer-plugins/tree/main/storage-s3)

### Cache
Expand Down Expand Up @@ -53,6 +54,8 @@ Using the third-party user system to manage users. For example: WeCom
The Notification plugin helps us to send messages to third-party notification systems. For example: Slack.

- [x] [Slack](https://github.com/apache/incubator-answer-plugins/tree/main/notification-slack)
- [x] [Lark](https://github.com/apache/incubator-answer-plugins/tree/main/notification-lark)
- [x] [Ding talk](https://github.com/apache/incubator-answer-plugins/tree/main/notification-dingtalk)

### Route

Expand Down
14 changes: 7 additions & 7 deletions captcha-google-v2/i18n/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
package i18n

const (
InfoName = "plugin.google_v2_captcha.backend.info.name"
InfoDescription = "plugin.google_v2_captcha.backend.info.description"
ConfigSiteKeyTitle = "plugin.google_v2_captcha.backend.config.site_key.title"
ConfigSiteKeyDescription = "plugin.google_v2_captcha.backend.config.site_key.description"
ConfigSecretKeyTitle = "plugin.google_v2_captcha.backend.config.secret_key.title"
ConfigSecretKeyDescription = "plugin.google_v2_captcha.backend.config.secret_key.description"
ConfigSiteVerifyEndpointTitle = "plugin.google_v2_captcha.backend.config.site_verify_endpoint.title"
InfoName = "plugin.google_v2_captcha.backend.info.name"
InfoDescription = "plugin.google_v2_captcha.backend.info.description"
ConfigSiteKeyTitle = "plugin.google_v2_captcha.backend.config.site_key.title"
ConfigSiteKeyDescription = "plugin.google_v2_captcha.backend.config.site_key.description"
ConfigSecretKeyTitle = "plugin.google_v2_captcha.backend.config.secret_key.title"
ConfigSecretKeyDescription = "plugin.google_v2_captcha.backend.config.secret_key.description"
ConfigSiteVerifyEndpointTitle = "plugin.google_v2_captcha.backend.config.site_verify_endpoint.title"
ConfigSiteVerifyEndpointDescription = "plugin.google_v2_captcha.backend.config.site_verify_endpoint.description"
)
4 changes: 2 additions & 2 deletions captcha-google-v2/recaptcha.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type Captcha struct {
}

type CaptchaConfig struct {
SiteKey string `json:"site_key"`
SecretKey string `json:"secret_key"`
SiteKey string `json:"site_key"`
SecretKey string `json:"secret_key"`
SiteVerifyEndpoint string `json:"site_verify_endpoint"`
}

Expand Down
4 changes: 2 additions & 2 deletions embed-basic/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/apache/incubator-answer-plugins/embed-basic
go 1.19

require (
github.com/apache/incubator-answer v1.3.6
github.com/apache/incubator-answer v1.4.0
github.com/apache/incubator-answer-plugins/util v1.0.2
github.com/gin-gonic/gin v1.9.1
)

require (
Expand All @@ -14,7 +15,6 @@ require (
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions embed-basic/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/BurntSushi/toml v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU
github.com/BurntSushi/toml v1.0.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/LinkinStars/go-i18n/v2 v2.2.2 h1:ZfjpzbW13dv6btv3RALKZkpN9A+7K1JA//2QcNeWaxU=
github.com/LinkinStars/go-i18n/v2 v2.2.2/go.mod h1:hLglSJ4/3M0Y7ZVcoEJI+OwqkglHCA32DdjuJJR2LbM=
github.com/apache/incubator-answer v1.3.6 h1:OddJdWqDrgIKY2wnLOipT3mjNI9h7fLNc4eEyyUp+hs=
github.com/apache/incubator-answer v1.3.6/go.mod h1:YKwpG0rwRC0kHcbILcIyIbPMwsWaZ8j5lHJ34DPIdMI=
github.com/apache/incubator-answer v1.4.0 h1:W3y4TAQ4sdzgcqntGqNBPe0BdyeW7+l8FWYBDs9g8+Y=
github.com/apache/incubator-answer v1.4.0/go.mod h1:Q4NkQmBd0sV7t3Cd8NBsWh9w8jFRo/2qjzOw9MlRNwk=
github.com/apache/incubator-answer-plugins/util v1.0.2 h1:PontocVaiEm+oTj+4aDonwWDZnxywUeHsaTwlQgclfA=
github.com/apache/incubator-answer-plugins/util v1.0.2/go.mod h1:KPMSiM4ec4uEl2njaGINYuSl6zVmHdvPB2nHUxVcQDo=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
Expand Down
2 changes: 1 addition & 1 deletion embed-basic/info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

slug_name: basic_embed
type: editor
version: 1.0.4
version: 1.0.5
author: answerdev
link: https://github.com/apache/incubator-answer-plugins/tree/main/embed-basic
20 changes: 20 additions & 0 deletions notification-dingtalk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Ding talk Notification

## Feature

- Send message to Ding talk

## Config

> Config Webhook URL and open the notification
- Webhook URL: such as `https://oapi.dingtalk.com/robot/send?access_token=xxxxxx`

## Preview

![Ding talk Config](./docs/dingtalk-config.png)

## Document

- https://open.dingtalk.com/document/robots/custom-robot-access
- https://open.dingtalk.com/document/orgapp/custom-bot-send-message-type
53 changes: 53 additions & 0 deletions notification-dingtalk/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package dingtalk

import (
"encoding/json"

"github.com/apache/incubator-answer-plugins/notification-dingtalk/i18n"
"github.com/apache/incubator-answer/plugin"
)

type NotificationConfig struct {
Notification bool `json:"notification"`
}

func (n *Notification) ConfigFields() []plugin.ConfigField {
return []plugin.ConfigField{
{
Name: "notification",
Type: plugin.ConfigTypeSwitch,
Title: plugin.MakeTranslator(i18n.ConfigNotificationTitle),
Description: plugin.MakeTranslator(i18n.ConfigNotificationDescription),
UIOptions: plugin.ConfigFieldUIOptions{
Label: plugin.MakeTranslator(i18n.ConfigNotificationLabel),
},
Value: n.Config.Notification,
},
}
}

func (n *Notification) ConfigReceiver(config []byte) error {
c := &NotificationConfig{}
_ = json.Unmarshal(config, c)
n.Config = c
return nil
}
166 changes: 166 additions & 0 deletions notification-dingtalk/dingtalk_notification.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package dingtalk

import (
"embed"
"github.com/apache/incubator-answer-plugins/util"
"github.com/go-resty/resty/v2"
"strings"

dingtalkI18n "github.com/apache/incubator-answer-plugins/notification-dingtalk/i18n"
"github.com/apache/incubator-answer/plugin"
"github.com/segmentfault/pacman/i18n"
"github.com/segmentfault/pacman/log"
)

//go:embed info.yaml
var Info embed.FS

type Notification struct {
Config *NotificationConfig
UserConfigCache *UserConfigCache
}

func init() {
uc := &Notification{
Config: &NotificationConfig{},
UserConfigCache: NewUserConfigCache(),
}
plugin.Register(uc)
}

func (n *Notification) Info() plugin.Info {
info := &util.Info{}
info.GetInfo(Info)

return plugin.Info{
Name: plugin.MakeTranslator(dingtalkI18n.InfoName),
SlugName: info.SlugName,
Description: plugin.MakeTranslator(dingtalkI18n.InfoDescription),
Author: info.Author,
Version: info.Version,
Link: info.Link,
}
}

// GetNewQuestionSubscribers returns the subscribers of the new question notification
func (n *Notification) GetNewQuestionSubscribers() (userIDs []string) {
for userID, conf := range n.UserConfigCache.userConfigMapping {
if conf.AllNewQuestions {
userIDs = append(userIDs, userID)
}
}
return userIDs
}

// Notify sends a notification to the user
func (n *Notification) Notify(msg plugin.NotificationMessage) {
log.Debugf("try to send notification %+v", msg)

if !n.Config.Notification {
return
}

// get user config
userConfig, err := n.getUserConfig(msg.ReceiverUserID)
if err != nil {
log.Errorf("get user config failed: %v", err)
return
}
if userConfig == nil {
log.Debugf("user %s has no config", msg.ReceiverUserID)
return
}

// check if the notification is enabled
switch msg.Type {
case plugin.NotificationNewQuestion:
if !userConfig.AllNewQuestions {
log.Debugf("user %s not config the new question", msg.ReceiverUserID)
return
}
case plugin.NotificationNewQuestionFollowedTag:
if !userConfig.NewQuestionsForFollowingTags {
log.Debugf("user %s not config the new question followed tag", msg.ReceiverUserID)
return
}
default:
if !userConfig.InboxNotifications {
log.Debugf("user %s not config the inbox notification", msg.ReceiverUserID)
return
}
}

log.Debugf("user %s config the notification", msg.ReceiverUserID)

if len(userConfig.WebhookURL) == 0 {
log.Errorf("user %s has no webhook url", msg.ReceiverUserID)
return
}

notificationMsg, notificationTitle := renderNotification(msg)
// no need to send empty message
if len(notificationMsg) == 0 {
log.Debugf("this type of notification will be drop, the type is %s", msg.Type)
return
}

// Create a Resty Client
client := resty.New()
resp, err := client.R().
SetHeader("Content-Type", "application/json").
SetBody(NewWebhookReq(notificationMsg, notificationTitle)).
Post(userConfig.WebhookURL)

if err != nil {
log.Errorf("send message failed: %v %v", err, resp)
} else {
log.Infof("send message to %s success, resp: %s", msg.ReceiverUserID, resp.String())
}
}

func renderNotification(msg plugin.NotificationMessage) (string, string) {
lang := i18n.Language(msg.ReceiverLang)
switch msg.Type {
case plugin.NotificationUpdateQuestion:
return plugin.TranslateWithData(lang, dingtalkI18n.TplUpdateQuestion, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplUpdateQuestionTitle, nil)
case plugin.NotificationAnswerTheQuestion:
return plugin.TranslateWithData(lang, dingtalkI18n.TplAnswerTheQuestion, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplAnswerTheQuestionTitle, nil)
case plugin.NotificationUpdateAnswer:
return plugin.TranslateWithData(lang, dingtalkI18n.TplUpdateAnswer, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplUpdateAnswerTitle, nil)
case plugin.NotificationAcceptAnswer:
return plugin.TranslateWithData(lang, dingtalkI18n.TplAcceptAnswer, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplAcceptAnswerTitle, nil)
case plugin.NotificationCommentQuestion:
return plugin.TranslateWithData(lang, dingtalkI18n.TplCommentQuestion, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplCommentQuestionTitle, nil)
case plugin.NotificationCommentAnswer:
return plugin.TranslateWithData(lang, dingtalkI18n.TplCommentAnswer, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplCommentAnswerTitle, nil)
case plugin.NotificationReplyToYou:
return plugin.TranslateWithData(lang, dingtalkI18n.TplReplyToYou, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplReplyToYouTitle, nil)
case plugin.NotificationMentionYou:
return plugin.TranslateWithData(lang, dingtalkI18n.TplMentionYou, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplMentionYouTitle, nil)
case plugin.NotificationInvitedYouToAnswer:
return plugin.TranslateWithData(lang, dingtalkI18n.TplInvitedYouToAnswer, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplInvitedYouToAnswerTitle, nil)
case plugin.NotificationNewQuestion, plugin.NotificationNewQuestionFollowedTag:
msg.QuestionTags = strings.Join(strings.Split(msg.QuestionTags, ","), ", ")
return plugin.TranslateWithData(lang, dingtalkI18n.TplNewQuestion, msg), plugin.TranslateWithData(lang, dingtalkI18n.TplNewQuestionTitle, nil)
}
return "", ""
}
Binary file added notification-dingtalk/docs/dingtalk-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions notification-dingtalk/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module github.com/apache/incubator-answer-plugins/dingtalk

go 1.21.3

require (
github.com/apache/incubator-answer v1.4.0
github.com/apache/incubator-answer-plugins/util v1.0.2
github.com/go-resty/resty/v2 v2.15.3
github.com/segmentfault/pacman v1.0.5-0.20230822083413-c0075a2d401f
)

require (
github.com/LinkinStars/go-i18n/v2 v2.2.2 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/microcosm-cc/bluemonday v1.0.21 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/segmentfault/pacman/contrib/i18n v0.0.0-20230516093754-b76aef1c1150 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
Loading

0 comments on commit 2d97fc5

Please sign in to comment.