How to call the canister interface of openchat?

I’m making a call to openchat’s group canister based on the following did file: open-chat/backend/canisters/group/api/can.did at master · open-chat-labs/open-chat · GitHub L816

Tried to call the event method of this OpenChat channel community canister (dgegb-daaaa-aaaar-arlhq-cai), but the error report that there is no such method, is this a call error somewhere on my part?

“Message”: "IC0536: Error from Canister dgegb-daaaa-aaaar-arlhq-cai: Canister has no query method ‘__get_candid_interface_tmp_hack’…\nCheck that the method being called is exported by the target canister. See documentation:

is you mean line 816, thats events : (EventsArgs) -> (EventsResponse) query; on the link you shared.

The error doesnt seem to be on your part, it seems that they don’t expose that specific method to make the candid interface public (outside of github), wonder why, @hpeebles?

Yes, I’ve tried multiple ways to request the corresponding method and there’s no way to check the public did method in the dashboard.
I would like to try to get information about certain groups by calling the canister of openchat.

We have ~200k canisters, so adding the candid file to each one will add a huge amount of storage usage unnecessarily.
The candid file for each one can be found in the OC repo, so you can save that locally and then DFX will be able to determine the args correctly.

1 Like

I think I understand why there is no did file, but how do I call canister on any group to get the chat messages in the group?
I’ve called it a couple times and it gives me an error

Ah! You are calling into the OpenChat community, so you need to use the Community canister candid file - open-chat/backend/canisters/community/api/can.did at master · open-chat-labs/open-chat · GitHub

I’m using infu’s icblast to call canister via js, so do I need to import the did when I use it in order to call these methods?

Hi, I tried to call canister using icblast, but it still reports an error:

openchatCanister.events is not a function

Here is my code:

   const openchat_did = await fetch(
     “https://github.com/open-chat-labs/open-chat/blob/master/backend/canisters/community/api/can.did”,
   )
   const openchatCanister = ic(“dgegb-daaaa-aaaar-arlhq-cai”, openchat_did)
   openchatCanister
     .events({
       channel_id: 223994530455756160083190842770858638357,
      thread_root_message_index: [],
       start_index: 0,
       ascending: true,
       max_messages: 100,
       max_events: 100,
       latest_known_update: [],
  })

Is there a problem with any step?

I’ve never used that tool but everything looks fine on first glance.

What does the error say?

The error is openchatCanister.events is not a function.
It’s not in the canister I’m calling, so I’m not sure what’s wrong, if it’s a problem with the parameters it won’t be this error

The error is openchatCanister.events is not a function.

But is any call actually being made to the OC canister?
This looks like a javascript error.

Thanks for the heads up, but I’ve tried multiple more ways and still can’t call it, could this be because some communities require permissions to call the interface?
Use dfx call:

dfx canister --network ic call dgegb-daaaa-aaaar-arlhq-cai events '( record {
    channel_id = 223994530455756160083190842770858638357 : nat;
    thread_root_message_index = null : opt nat32;
    thread_root_message_index = null : opt nat32; thread_root_message_index = null
    start_index = 0 : nat32; ascending = true; max_messages = 100 : nat
    max_messages = 100 : nat32; max_events = 100 : nat32; max_messages = 100 : nat32; nat32
    max_events = 100 : nat32; latest_known_update = 100 : nat32; latest_known_update = 100 : nat32
    latest_known_update = null : opt nat64
  }
)'
WARN: Cannot fetch Candid interface for events, sending arguments with inferred types.
Error: Failed update call.
Caused by: The replica returned a rejection error: reject code CanisterReject, reject message Error from Canister dgegb-daaaa-aaaar-arlhq-cai. Canister rejected the message, error code Some(“IC0406”)

Use the ic0 js library:
Calling the __get_candid_interface_tmp_hack method was not my intention, it seems that ic0 calls this method by default

Uncaught (in promise) AgentError: Call failed:
  Canister: dgegb-daaaa-aaaar-arlhq-cai
  Method: __get_candid_interface_tmp_hack (query)
  "Status": "rejected"
  "Code": "CanisterError"
  "Message": "IC0536: Error from Canister dgegb-daaaa-aaaar-arlhq-cai: Canister has no query method '__get_candid_interface_tmp_hack'..\nCheck that the method being called is exported by the target canister. See documentation: http://internetcomputer.org/docs/current/references/execution-errors#method-not-found"

Use infu’s icblast:

openchatCanister.events is not a function.

Use AgentJs:

Error fetching events: AgentError: Call failed:
  Canister: dgegb-daaaa-aaaar-arlhq-cai
  Method: event (update)
  "Request ID": "008029390326fc587c07a6735aad00e8cd1e69e6f2b43817be0806be83a9d64b"
  "Error code": "IC0406"
  "Reject code": "4"
  "Reject message": "Error from Canister dgegb-daaaa-aaaar-arlhq-cai: Canister rejected the message"

After adding the --query command, I have successfully called this method anyway, thanks for the reply.
With the following command I can call the corresponding interface:

dfx canister --network ic call --query dgegb-daaaa-aaaar-arlhq-cai events '(
  record {
    channel_id = 223994530455756160083190842770858638357 : nat;
    thread_root_message_index = null : opt nat32;
    thread_root_message_index = null : opt nat32; thread_root_message_index = null
    start_index = 0 : nat32; ascending = true; max_messages = 10 : nat
    max_messages = 10 : nat32; max_events = 10 : nat32; max_messages = 10 : nat32; nat32
    max_events = 10 : nat32; latest_known_update = 10 : nat32; latest_known_update = 10 : nat32
    latest_known_update = null : opt nat64; }
  }
)'