Hello All,
I am creating a ChatBot using NetBeans 11.1. I am getting this error in DMS while loading of Bot.
ERROR [BotsManager] - ChatBotFactory service not found in jar AmazonLexRestAccess_V1-1-jar-with-dependencies.jar
ERROR [BotsManager] - Failed to load bot plugin from: AmazonLexRestAccess_V1-1-jar-with-dependencies.jar
Below is the code:-
AmazonLexRestAccess_V1.java
public class AmazonLexRestAccess_V1 implements ChatBot {
private ChatBotPlatform cbpInstance;
private Logger logger; // bot-session aware logger
private GenesysChatSession session;
@Override
public void setCbpInstance(ChatBotPlatform cbpInstance) {
this.cbpInstance = cbpInstance;
this.logger = cbpInstance.getLogger();
}
@Override
public void onCommandStart(GenesysChatSession session, int eventJoinedId, EspRequestParameters espParameters) {
// TODO to be implemented
this.session = session;
cbpInstance.sendMessage("Thank you for contact Thermo Fisher scientific!! How may i help you today?");
}
@Override
public void onCommandStop(StopReason reason, ChatEventInfo eventInfo, EspRequestParameters espParameters) {
// TODO to be implemented
}
@Override
public void onSessionActivity(ChatEventInfo eventInfo) {
// TODO to be implemented
ChatUserInfo originator = session.getParticipant(eventInfo.getUserId());
if (eventInfo.getEventType() == EventType.MESSAGE && originator.getUserType() != UserType.SYSTEM && originator.getUserType() != UserType.EXTERNAL)
{
if (eventInfo.getMessageText().matches("stop(:(keep_alive|force_close|close_if_no_agents))?"))
{
Action action = Action.KEEP_ALIVE;
String[] tokens = eventInfo.getMessageText().split(":");
if (tokens.length > 1)
{
action = Action.valueOf(tokens[1].toUpperCase());
}
// The bot decides to stop execution.
// The bot will be removed from chat session and discarded in BGS.
// If running in waiting mode, the interaction will be released in workflow.
// If the bot need to communicate something to workflow, it could invoke updateUserdata at this moment.
logger.info("Leaving chat session with after-action: " + action.name());
cbpInstance.leaveSession(action);
}
else
{
logger.info("Message Typed"+eventInfo.getMessageText());
cbpInstance.sendMessage(eventInfo.getMessageText());
AWSCredentials awsCreds=new BasicAWSCredentials("AccessKey","SecretKey");
//AmazonLexModelBuilding buildClient=AmazonLexModelBuildingClientBuilder
AmazonLexRuntime client= AmazonLexRuntimeClientBuilder.standard().withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(awsCreds)).build();
cbpInstance.sendMessage("Creds sent");
PostTextRequest postRequest=new PostTextRequest();
postRequest.setBotAlias("BookATrip_VFirst");
postRequest.setBotName("BookATrip_VFirst");
postRequest.setUserId("BotAccessRestAPI");
postRequest.setInputText(eventInfo.getMessageText());
cbpInstance.sendMessage("RequestMessage sent");
logger.info("Message Executed Till Build PostRequest");
PostTextResult textResult=client.postText(postRequest);
cbpInstance.sendMessage(textResult.getMessage());
logger.info("Echoing back message: " + eventInfo.getMessageText());
cbpInstance.sendMessage(eventInfo.getMessageText());
cbpInstance.sendMessage(eventInfo.getMessageText());
}
}
}
@Override
public void onCommandUpdate(EspRequestParameters espParameters) {
// TODO to be implemented
}
}
AmazonLexRestAccess_V1Factory
public class AmazonLexRestAccess_V1Factory implements ChatBotFactory {
private static final Logger LOG = LoggerFactory.getLogger(AmazonLexRestAccess_V1Factory.class);
public void initialize(KeyValueMap configuration) {
// TODO to be implemented
}
public void configurationUpdated(KeyValueMap configuration) {
// TODO to be implemented
}
public void shutdown() {
// TODO to be implemented
}
public ChatBot createChatBot(KeyValueMap espParameters, ChatInteractionInfo interactionInfo, BotCreationAttributes botCreationAttributes) {
return new AmazonLexRestAccess_V1();
}
@Override
public String getBotId() {
return "AmazonLexRestAccess_V1";
}
}