erictik / midjourney-api

MidJourney client. Unofficial Node.js client
Apache License 2.0
1.65k stars 271 forks source link

Add option to send prompts directly to Midjourney Bot via DM #71

Open treefort opened 1 year ago

treefort commented 1 year ago

For accounts with the pro plan, prompts are done via Midjourney Bot DMs. Are DMs sent via the same mechanism as regular channels? How about the WS communication?

If not, it would be nice to have an option to send commands directly to the Midjourney Bot. If you can provide some guidance, I don't mind putting a PR together.

zcpua commented 1 year ago

https://github.com/erictik/midjourney-api/blob/main/src/interfaces/config.ts#L7 https://github.com/erictik/midjourney-api/blob/main/src/midjourney.ts#L101 try ServerId undefined or create a server and add Midjourney Bot to it

treefort commented 1 year ago

Thanks for the suggestions-- I tried both approaches and I get "Error: ImagineApi failed with status 400."

ejkkan commented 1 year ago

Did you resolve this? Also on the pro plan and I want to be able to trigger imagine commands via the api and then fetch it at a later point. Either awaiting the image being created or if it can be polled by a generating id(something of the sort).

treefort commented 1 year ago

awaiting the image being created or if it can be polled by a generating id

The library actually does this already with the websockets (Ws) option set to true. I added a callback here that passed the status messages that come over the websocket to a callback function that updated an entry in my db for that particular prompt.

I couldn't get the Midjourney Bot DM thing sorted, so I just ended up adding the bot to my own discord and you can use the commands in any channel.

ejkkan commented 1 year ago

Cool! So how'd do you get the setup working for you pro plan?

If I try to set Salai, Channel and Server Id's for my private Midjouney bot I'm getting: Error: ImagineApi failed with status 400

And If trying what zcpua suggest above and leave out he server id I get: Error: ServerId, ChannelId and SalaiToken are required

I'm not out to use it as a chat bot, but as a hosted api to send a prompt and store the image in my db.

zcpua commented 1 year ago

https://github.com/erictik/midjourney-api/blob/main/example/imagine-dm.ts

ejkkan commented 1 year ago

@zcpua Thanks, I've re-cloned and tried the imagine-dm.ts variant. I've just checked that my SALAI_TOKEN is up to date and I still get ImagineApi failed with status 400

imagine-ws.ts now works without appending server-, channel-ids. But it also throws 400s

zcpua commented 1 year ago

https://discord.com/invite/GavuGHQbV4

ejkkan commented 1 year ago

@zcpua in, who do i reach out to? 😅

zcpua commented 1 year ago
export SERVER_ID="1082500871478329374"
export CHANNEL_ID="1094892992281718894"
export SALAI_TOKEN="your-salai-token"

try again

ejkkan commented 1 year ago

Still seeing the 400s with this setup.

Though I'm not exporting the config, I'm setting the env like this:

SALAI_TOKEN="*my salai token*"(authorization header from the requests)
SERVER_ID="108250087147832934"
CHANNEL_ID="109489299228171884"

Trying to log the reponses but they're not giving any messages on what seems to be wrong.

treefort commented 1 year ago

@ejkkan try using server/channel IDs from the official discord just to rule out a bad config?

ejkkan commented 1 year ago

It works if I use the setup from your discord channel. But I can't get it working when trying to use my own direct messages bot.