I want to create something liek
const msg = await client.createTextMessage(finalized=false, "Hello group!"); await client.sendMessage(msg);
and deploy it on icp
I tried npx create-openchat-bot
but too complex
i want to do it just like telegram bots
My best option
#[query]
async fn say_hi_open_chat(name: String) -> String {
return format!(name, 'Hello, {name}')
}
- In this case I already have canister, I just want to call this from my oc.app chatbot
Goal
- Extract data from public groups
- post a message in public groups
Hey, try this out.
const { HttpAgent, Actor } = require('@dfinity/agent');
const { Principal } = require('@dfinity/principal');
// Yo, replace with your actual OpenChat Bot Canister ID
const CANISTER_ID = 'your-openchat-bot-canister-id';
// Here’s the simplified Candid interface — just a send function for messages
const idlFactory = ({ IDL }) => {
return IDL.Service({
send: IDL.Func([
IDL.Record({
chatId: IDL.Nat,
message: IDL.Text,
}),
], [IDL.Text], []),
});
};
async function main() {
const agent = new HttpAgent({ host: 'https://ic0.app' });
// Optional — if you're testing locally or in dev mode
// await agent.fetchRootKey();
const bot = Actor.createActor(idlFactory, {
agent,
canisterId: CANISTER_ID,
});
const chatId = 42; // Yeah, replace with the actual chat ID
const message = "Hello group!"; // Or whatever message you want
const response = await bot.send({ chatId, message });
console.log("Response:", response);
}
main().catch(console.error);
I’m not sure, maybe @icpjesse can help out.
1 Like
Tagging in the pros to help @hpeebles @julianjelfs
The first thing to decide is what technology stack do you want to use for your bot. This will depend on what programming language you are familiar with and what you are trying to achieve. For an on chain bot you can use rust or motoko and for off chain you can use rust or typescript. I theory you could use any tech stack for an off chain bot but we only have sdk support for rust and typescript.
Having made your decision you can find examples for each kind of bot in our sdk repo: GitHub - open-chat-labs/open-chat-bots: SDKs for building Bots for OpenChat with examples.
You will also find docs on how to get started there.
1 Like
OpenChat does not host your bot, that’s up to you. You will just have to tell OpenChat (via /register_bot) where it can reach your bot.
1 Like