# How to create openchat bot?

**URL:** <https://forum.dfinity.org/t/how-to-create-openchat-bot/45691>\
**Category:** Developers\
**Created:** [May 1, 2025, 9:23am UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691 "2025-05-01T09:23:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AliSci](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/alisci/32/33799_2.png) [@AliSci](https://forum.dfinity.org/u/AliSci)\
**Post date:** [May 1, 2025, 9:23am UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691/1 "2025-05-01T09:23:44Z")

</div>

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

```auto
#[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

1. Extract data from public groups
2. post a message in public groups

---

<div class="post-metadata">

**Author:** ![Phasma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/phasma/32/27069_2.png) [@Phasma](https://forum.dfinity.org/u/Phasma)\
**Post date:** [May 1, 2025, 9:38am UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691/2 "2025-05-01T09:38:06Z")

</div>

Hey, try this out.

```auto
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);
```

---

<div class="post-metadata">

**Author:** ![AliSci](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/alisci/32/33799_2.png) [@AliSci](https://forum.dfinity.org/u/AliSci)\
**Post date:** [May 1, 2025, 9:43am UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691/3 "2025-05-01T09:43:33Z")

</div>

- what are the host/deployment options ?
- how to get `your-openchat-bot-canister-id` is there tutorial to get started
- is there oc api?

---

<div class="post-metadata">

**Author:** ![AliSci](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/alisci/32/33799_2.png) [@AliSci](https://forum.dfinity.org/u/AliSci)\
**Post date:** [May 1, 2025, 10:01am UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691/4 "2025-05-01T10:01:14Z")

</div>

I also found this [open-chat-bots/GETSTARTED.md at main · open-chat-labs/open-chat-bots · GitHub](https://github.com/open-chat-labs/open-chat-bots/blob/main/GETSTARTED.md) for runing it locally but i want to deploy it right away

---

<div class="post-metadata">

**Author:** ![Phasma](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/phasma/32/27069_2.png) [@Phasma](https://forum.dfinity.org/u/Phasma)\
**Post date:** [May 1, 2025, 10:34am UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691/5 "2025-05-01T10:34:08Z")

</div>

I’m not sure, maybe @icpjesse can help out.

---

<div class="post-metadata">

**Author:** ![icpjesse](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/icpjesse/32/19558_2.png) [@icpjesse](https://forum.dfinity.org/u/icpjesse)\
**Post date:** [May 4, 2025, 1:54am UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691/6 "2025-05-04T01:54:09Z")

</div>

Tagging in the pros to help @hpeebles @julianjelfs

---

<div class="post-metadata">

**Author:** ![julianjelfs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/julianjelfs/32/8481_2.png) [@julianjelfs](https://forum.dfinity.org/u/julianjelfs)\
**Post date:** [May 4, 2025, 12:00pm UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691/7 "2025-05-04T12:00:57Z")

</div>

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](https://github.com/open-chat-labs/open-chat-bots).

You will also find docs on how to get started there.

---

<div class="post-metadata">

**Author:** ![julianjelfs](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/julianjelfs/32/8481_2.png) [@julianjelfs](https://forum.dfinity.org/u/julianjelfs)\
**Post date:** [May 4, 2025, 12:03pm UTC](https://forum.dfinity.org/t/how-to-create-openchat-bot/45691/8 "2025-05-04T12:03:52Z")

</div>

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.
