echo-bot icon indicating copy to clipboard operation
echo-bot copied to clipboard

Adding Bot to existing conversation.

Open funmaker opened this issue 9 years ago • 10 comments

There should be a way to add bot to existing conversation or let bot change conversation to existing one. It would also allow multiple bots to join one conversation.

funmaker avatar Dec 24 '16 20:12 funmaker

Bot API allows this even now. Some work is needed on the Clients' side to utilize this. Keep in mind:

  1. Bots cannot make any changes on conversations except posting into those they are currently in.
  2. Users, on the other hand, can add/remove bots ( one or many) to any conversation they are in.

dkovacevic avatar Dec 25 '16 13:12 dkovacevic

Well according to wiki, bot is assigned only to one and only conversation:

A bot is created and destroyed as it is added and removed from a conversation, respectively, i.e. it is scoped to a single conversation and its lifecycle bound to its membership in that conversation.

When I try to add bot to conversation I cannot find it on my connections list. I'm sure it's because when you start using your bot you are not connected with it, invite link only creates conversation with it. When I try to connect with bot it never accepts my request. I took a look at decompiled BotClient.java and function that is responsible for accepting new connections BotClinet::acceptConnection is empty. UserClient.java however does support accepting connections and I managed to archive my goal using kind of Bot-User hybrid but I believe this is not how bot API was intended. Also from HTTP API(especially /bot/conversation) it appears bots are intended to be part of only one conversation per instance.

I think I'm missing something. Could you provide step by step instructions to add bot to existing conversation?

funmaker avatar Dec 25 '16 16:12 funmaker

Currently Wire Clients do not support adding bots to existing conversations. We are working on it. However you could do it manually using curl. Data-Flow ProviderId and ServiceId could be obtained through DevBot by calling: get self and show bot<botname> respectively

dkovacevic avatar Dec 25 '16 20:12 dkovacevic

Where am I supposed to send that request? /conversations/:id/bots is not defined anywhere in API Service I tried to send it to my bot service and received: {"code":404,"message":"HTTP 404 Not Found"}

Also what does the :id in the url means? I assumed it's id of the conversation. I couldn't find any way to get conversation id using DevBot, but I found that there is some id in DOM data fields in buttons in online app and I assumed this is it.

funmaker avatar Dec 27 '16 19:12 funmaker

For that you would have to open web app from: app.wire.com, open console and check http requests sent to BE when posting to conversations. But this is already way out of scope of Bots and its API. Feel free to contact me on Wire and I can help you with this. My username is @dejan

dkovacevic avatar Dec 27 '16 20:12 dkovacevic

Here is a short info how I added my BOT to conversation after a chat with Dejan.

HTTP request to BA to add your BOT to a conversation

TOKEN is a bearer token used to send requests to the backend. Easiest way is to use the web app and dev tools or launch desktop electron app (after killing all Wire related process) using wire.exe --devtools

CONVID is conversation ID. Also can be obtained via dev tools. you'll see it in requests.

cutl -XPOST -H "Content-Type: application/json" \
            -H "Authorization: Bearer $TOKEN" \
            https://prod-nginz-https.wire.com/conversations/$CONVID/bots [email protected] | python -mjson.tool

Parameters for body requests can be obtained from devbot chat using get self and show bot <your_bot_name>

params.json

{
    "provider": "<ID from get self on devbot channel>",
    "service": "<ID from show bot <NAME> on devbot channel>"
}

grmpyninja avatar Jan 06 '17 12:01 grmpyninja

@grmpyninja Thanks for summarizing those chats. I have added another doc to our Wiki: User Services

dkovacevic avatar Jan 12 '17 12:01 dkovacevic

Additionally on Web App you can

  • Select the conv you would like to add a bot into
  • Open console
  • type: wire.app.repository.bot.add_bot("git", false)

This command will add bot called: git to the current conv

dkovacevic avatar May 16 '17 14:05 dkovacevic

The JS API has changed somewhat since @dkovacevic posted. Instead of typing: wire.app.repository.bot.add_bot("<bot_name>", false) use wire.app.repository.bot.add_bot({botName: "<bot_name>", botProvider: "<bot_provider>", botService: "<bot_service>"}, false)

Where bot_service and bot_provider can be found in the URL for adding a bot to a one-on-one conversation.

For reference this is where the API can be found: https://github.com/wireapp/wire-webapp/blob/prod/app/script/bot/BotRepository.js

cruatta avatar Jan 20 '18 18:01 cruatta

#43

dkovacevic avatar Feb 11 '19 19:02 dkovacevic