I am new to Rust programming language and I am trying to create a Telegram bot using the Teloxide library. I am having an issue with passing an instance of the "Eliza" struct to the "answer" function, which is used as a callback by the "repl" function. I have tried different methods such as creating a struct with "Eliza" inside and making "answer" a method of the struct to use "Eliza" implicitly in it, and also tried using "Lazy_static", but none of them seem to work. The only thing that works is instantiating "eliza" inside the "answer" function but it is not an efficient method as it takes up a lot of resources and does not remember the conversation. I have come across a trait called "Injectable" but I am unable to understand how to use it. As I am a beginner in rust, many basic things are not clear to me. Can anyone please help me out with this?
use teloxide::dptree::di::{Injectable, Asyncify, CompiledFn};
use teloxide::{prelude::*, utils::command::BotCommands};
use teloxide::repl;
use tokio;
use eliza::Eliza;
#[tokio::main]
async fn main() {
pretty_env_logger::init();
log::info!("Starting start bot...");
let bot = Bot::new("Token");
let ela = Eliza::from_file("src/ai-helper/doctor.json").unwrap();
repl(bot, answer).await;
}
fn answer(bot: Bot, msg: Message) -> ResponseResult<()> {
//i want eliza there
let cmd = Command::parse(msg.text().unwrap(), "");
match cmd {
Ok(Command::Start) => {
bot.send_message(msg.chat.id, /*eliza.greet()*/);
},
Ok(Command::Diagnosis) => {
bot.send_message(msg.chat.id, /*eliza.farewell()*/);
},
_ => {
bot.send_message(msg.chat.id, /*eliza.respond(msg.text().unwrap()*/));
}
}
Ok(())
}