1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.chatbotrecorder.business;
35
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.UUID;
40 import fr.paris.lutece.plugins.chatbot.business.BotDescription;
41 import fr.paris.lutece.plugins.chatbot.service.BotService;
42 import fr.paris.lutece.plugins.chatbot.service.bot.ChatBot;
43 import fr.paris.lutece.portal.web.l10n.LocaleService;
44 import fr.paris.lutece.util.url.UrlItem;
45
46 public final class ChatBotApp
47 {
48
49 private static final String PARAMETER_BOT = "bot";
50 private static final String PARAMETER_LANGUAGE = "lang";
51
52 private static final String URL_BOT = "jsp/admin/plugins/chatbotrecorder/ManageScenarios.jsp";
53
54
55
56
57
58
59 public static List<BotDescription> getBotsDescription( )
60 {
61 List<BotDescription> list = new ArrayList<BotDescription>( );
62 for ( ChatBot bot : BotService.getBots( ) )
63 {
64 List<String> listLanguages = bot.getAvailableLanguages( );
65 if ( listLanguages != null )
66 {
67 for ( String strLanguage : listLanguages )
68 {
69 BotDescription botDescription = new BotDescription( );
70 Locale locale = new Locale( strLanguage );
71 botDescription.setName( bot.getName( locale ) );
72 botDescription.setDescription( bot.getDescription( locale ) );
73 botDescription.setLanguage( locale.getDisplayLanguage( ) );
74 botDescription.setAvatarUrl( bot.getAvatarUrl( ) );
75 UrlItem url = new UrlItem( URL_BOT );
76 url.addParameter( PARAMETER_BOT, bot.getKey( ) );
77 url.addParameter( PARAMETER_LANGUAGE, strLanguage );
78 botDescription.setUrl( url.getUrl( ) );
79 list.add( botDescription );
80 }
81 }
82 else
83 {
84 BotDescription botDescription = new BotDescription( );
85 Locale locale = LocaleService.getDefault( );
86 botDescription.setName( bot.getName( locale ) );
87 botDescription.setDescription( bot.getDescription( locale ) );
88 botDescription.setLanguage( locale.getDisplayLanguage( ) );
89 botDescription.setAvatarUrl( bot.getAvatarUrl( ) );
90 UrlItem url = new UrlItem( URL_BOT );
91 url.addParameter( PARAMETER_BOT, bot.getKey( ) );
92 url.addParameter( PARAMETER_LANGUAGE, locale.getLanguage( ) );
93 botDescription.setUrl( url.getUrl( ) );
94 list.add( botDescription );
95 }
96 }
97 return list;
98 }
99
100
101
102
103
104
105 public static String getNewConversationId( )
106 {
107 return UUID.randomUUID( ).toString( );
108 }
109 }