• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

digiteinfotech / kairon / 12112350604

02 Dec 2024 03:52AM UTC coverage: 89.891% (-0.04%) from 89.932%
12112350604

Pull #1611

github

web-flow
Merge 9176d03d1 into f2f296b80
Pull Request #1611: Mail channel implementation

383 of 434 new or added lines in 15 files covered. (88.25%)

12 existing lines in 2 files now uncovered.

24141 of 26856 relevant lines covered (89.89%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.34
/kairon/shared/channels/mail/data_objects.py
1
import time
1✔
2
from mongoengine import Document, StringField, ListField, FloatField, BooleanField
1✔
3
from kairon.exceptions import AppException
1✔
4

5

6

7

8
class MailClassificationConfig(Document):
1✔
9
    intent: str = StringField(required=True)
1✔
10
    entities: list[str] = ListField(StringField())
1✔
11
    subjects: list[str] = ListField(StringField())
1✔
12
    classification_prompt: str = StringField()
1✔
13
    reply_template: str = StringField()
1✔
14
    bot: str = StringField(required=True)
1✔
15
    user: str = StringField()
1✔
16
    timestamp: float = FloatField()
1✔
17
    status: bool = BooleanField(default=True)
1✔
18

19

20
    @staticmethod
1✔
21
    def create_doc(
1✔
22
            intent: str,
23
            entities: list[str],
24
            subjects: list[str],
25
            classification_prompt: str,
26
            reply_template: str,
27
            bot: str,
28
            user: str
29
    ):
30
        mail_config = None
1✔
31
        try:
1✔
32
            exists = MailClassificationConfig.objects(bot=bot, intent=intent).first()
1✔
33
            if exists and exists.status:
1✔
34
                raise AppException(f"Mail configuration already exists for intent [{intent}]")
1✔
35
            elif exists and not exists.status:
1✔
NEW
36
                exists.update(
×
37
                    entities=entities,
38
                    subjects=subjects,
39
                    classification_prompt=classification_prompt,
40
                    reply_template=reply_template,
41
                    timestamp=time.time(),
42
                    status=True,
43
                    user=user
44
                )
NEW
45
                mail_config = exists
×
46
            else:
47
                mail_config = MailClassificationConfig(
1✔
48
                    intent=intent,
49
                    entities=entities,
50
                    subjects=subjects,
51
                    classification_prompt=classification_prompt,
52
                    reply_template=reply_template,
53
                    bot=bot,
54
                    timestamp=time.time(),
55
                    status=True,
56
                    user=user
57
                )
58
                mail_config.save()
1✔
59

60
        except Exception as e:
1✔
61
            raise AppException(str(e))
1✔
62

63
        return mail_config
1✔
64

65
    @staticmethod
1✔
66
    def get_docs(bot: str):
1✔
67
        try:
1✔
68
            objs =  MailClassificationConfig.objects(bot=bot, status=True)
1✔
69
            return_data = []
1✔
70
            for obj in objs:
1✔
71
                data = obj.to_mongo().to_dict()
1✔
72
                data.pop('_id')
1✔
73
                data.pop('timestamp')
1✔
74
                data.pop('status')
1✔
75
                data.pop('user')
1✔
76
                return_data.append(data)
1✔
77
            return return_data
1✔
NEW
78
        except Exception as e:
×
NEW
79
            raise AppException(str(e))
×
80

81
    @staticmethod
1✔
82
    def get_doc(bot: str, intent: str):
1✔
83
        try:
1✔
84
            obj = MailClassificationConfig.objects(bot=bot, intent=intent, status=True).first()
1✔
85
            if not obj:
1✔
86
                raise AppException(f"Mail configuration does not exist for intent [{intent}]")
1✔
87
            data = obj.to_mongo().to_dict()
1✔
88
            data.pop('_id')
1✔
89
            data.pop('timestamp')
1✔
90
            data.pop('status')
1✔
91
            data.pop('user')
1✔
92
            return data
1✔
93
        except Exception as e:
1✔
94
            raise AppException(str(e))
1✔
95

96

97
    @staticmethod
1✔
98
    def delete_doc(bot: str, intent: str):
1✔
99
        try:
1✔
100
            MailClassificationConfig.objects(bot=bot, intent=intent).delete()
1✔
NEW
101
        except Exception as e:
×
NEW
102
            raise AppException(str(e))
×
103

104
    @staticmethod
1✔
105
    def soft_delete_doc(bot: str, intent: str):
1✔
106
        try:
1✔
107
            MailClassificationConfig.objects(bot=bot, intent=intent).update(status=False)
1✔
NEW
108
        except Exception as e:
×
NEW
109
            raise AppException(str(e))
×
110

111
    @staticmethod
1✔
112
    def update_doc(bot: str, intent: str, **kwargs):
1✔
113
        keys = ['entities', 'subjects', 'classification_prompt', 'reply_template']
1✔
114
        for key in kwargs.keys():
1✔
115
            if key not in keys:
1✔
116
                raise AppException(f"Invalid  key [{key}] provided for updating mail config")
1✔
117
        try:
1✔
118
            MailClassificationConfig.objects(bot=bot, intent=intent).update(**kwargs)
1✔
NEW
119
        except Exception as e:
×
NEW
120
            raise AppException(str(e))
×
121

122

123

124

125

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc