Discord Interprocess Communication - Read Messages - discord

I'd like to abide by TOS but i am having tough time. I'm in paid server where I can't place a bot account. I simply want to consume the message content in my application (currently in python). What can I do? Can I write a hook to consume the messages from the GUI or from the web client? It seems what I want to do is not supported. Any thoughts?
Others have stated that you can apparently use use ipc and messages.read scope or RPC to receive messages but I don't know what resources are available to hook into and get the message content as it comes from the server.

There are multiple ways to read the messages from the client. You could use the Discord API with your account's token, but this is not allowed by the Discord ToS and thus is bannable (self botting). The other way is to use Discord IPC.
Discord IPC allows you to communicate with the Discord client by using named pipes. The default name is discord-ipc-0. You need a Discord application to use it.
The IPC protocol uses the same protocol as RPC, which is documented on Discord Developer Portal. You can also find more information on the IPC protocol on the discord-rpc official repo.
To put it simply, the packets you send through the pipe are serialized that way:
uint32 opcode
uint32 length
byte[length] jsonData
The data is a JSON encoded object, with a unique nonce parameter that is sent back on the answer, a cmd parameter for the command you want to use and optionally args and evt.
You would probably be interested in the AUTHORIZE, AUTHENTICATE, GET_CHANNEL and SUBSCRIBE commands. So I'll explain those four commands here.
But first, you need to connect to the IPC and do the handshake. This is done by sending a message with the opcode 0, your client_id and the protocol version. Here's what the JSON object should look like:
{
"v": 1,
"client_id": 332269999912132097
}
Once you're connected, you should receive a DISPATCH response with the user info. Every message you will send from this point should use the opcode 1
Now, you need to send an AUTHORIZE command This command allows you to ask an OAuth2 code from the client with the specified scopes, which will allow you to use the AUTHENTICATE command. Here, you would want the rpc and messages.read scopes. It should look like this:
{
"nonce": "be9a6de3-31d0-4767-a8e9-4818c5690015",
"cmd": "AUTHORIZE",
"args": {
"client_id": 332269999912132097,
"scopes": "rpc messages.read"
}
}
Please note that you need a redirect uri on your application for this to work.
The client should get a prompt. If he accepts, then your application would receive an oauth2 code that you can use to authenticate. The OAuth2 process is explained on the Discord Developer Portal.
After making your request to /oauth2/token with the code, your client id, client secret and redirect uri, you should be getting an access token that you can to authenticate, using the AUTHENTICATE command. Here is what it should look like:
{
"nonce": "5dc0c062-98c6-47a0-8922-bbb52e9d6afa",
"cmd": "AUTHENTICATE",
"args": {
"access_token": "CZhtkLDpNYXgPH9Ml6shqh2OwykChw"
}
}
If the authentication is successful, you should receive a response with evt set to null, application info and user info.
From this point, you are authenticated and you can read messages by using the GET_CHANNEL command to get the last messages, and by subscribing to the MESSAGE_CREATE event to get the new messages when they're sent. Those are documented on the Developer Portal.

Related

Discord API: reading all messages from a channel

I'm trying to interact with the Discord API, created an application, and trying to use the following endpoint:
https://discord.com/api/channels/843835119579562035/messages?limit=50
However I get an error: 401, unauthorised. I am authenticated and have a proper access token, in fact, I'm able to use this endpoint: https://discord.com/api/users/#me/guilds
My user is added to the server of that channel.
My endgoal is to be able to monitor a channel and be notified of new messages in that channel, without actually adding a bot to the server. Is that even possible?
Thanks

Use Discord's API to send message as user

I want to send a message in a Discord channel but from a user account not a bot. Is this kind of thing possible using Discord's API?
The official documentation should contain enough information to get started: https://discord.com/developers/docs/resources/channel#create-message
Make sure to login with OAuth2 and not as a bot. Also, it is important to get the right scope (permissions) when requesting an OAuth token.

how can I send emails from react using sendinblue?

I am working in React applications (using the .net core in the back-end)
I have to send emails from the client side , we have to use sendinblue instead of mailgun , I need your help
You should not send emails from the client side.
Consider that in doing so, you're going to expose your API Key to any client, leading to a severe vulnerability for your application (anyone could impersonate you and send emails as if they were you).
In order to really make that work, you should perform an AJAX request to your server and there, connect to the Sendinblue API and make the request to send the email. In this case, the API Key could be safely stored in your server.

How can I trigger an API request using SMS?

Lets say I have 2 mobile phone numbers: X for Agent, Y for Merchant.
I want to be able to have a system where an SMS is sent from X to Y, and this triggers an API request in the Merchant's server, for example a POST request with data that looks something like this:
{
"mobile_number": X,
"type": "agent",
"amount": "240.00"
}
Hopefully you get the idea. How can I do this? Are there any readily available SaaS services that offer these things? Thanks.
If Y is going to be the receiving number that triggers the API request you could:
Get an account at https://portal.ytel.com/user/signup where you can
obtain a programmable SMS enabled number.
Buy an SMS enabled number in the portal or the API. Under number management put in a Webhook url under SMS Settings->SMS Request Url and this Webhook will post to the url any inbound SMS sent to it.
Parse the Posted Parameters to the URL for whatever you need from
it.
Execute a cURL request to your API endpoint and send over:
{"mobile_number": X,"type": "agent","amount": "240.00" }
Or whatever else you want, I'm assuming it will be different depending on what's sent in the SMS

Receive slack bot messages via requests to external URL

Is it possible to receive direct messages on behalf of a slack bot via POST requests to a certain domain?
I want to have an endpoint in Google App Engine that receives incoming direct messages from Slack via POST requests, and posts messages back via the API. Is it possible?
You can use the new Events API. Create a bot, subscribe to message.im events, and set your endpoint as the callback URL
You just need to set up an "outgoing webhook"in slack and point it to whatever endpoint you need on your GAE server. In order to respond just use an "incoming webhook" to receive the answer.

Resources