POST Discord Message Embed - javascript

Here is what Im using sending JSON body data.
{
"reactions": [
{
"count": 1,
"me": false,
"emoji": {
"id": null,
"name": "🔥"
}
}
],
"attachments": [],
"tts": false,
"embeds": [],
"timestamp": "2017-07-11T17:27:07.299000+00:00",
"mention_everyone": false,
"id": "334385199974967042",
"pinned": false,
"edited_timestamp": null,
"author": {
"username": "Mason",
"discriminator": "9999",
"id": "53908099506183680",
"avatar": "a_bab14f271d565501444b2ca3be944b25"
},
"mention_roles": [],
"content": "Supa Hot",
"channel_id": "290926798999357250",
"mentions": [],
"type": 0
}
I only recive the image below. I dont get any embed messages or anything I only get where "Content" is located.
So in theory you need JSON body data to embed messages, I am using a program that sends POST & GET requests. Discord will only take "content" data and post it in my webhook channel. I need to embed a message using JSON data. No language here, just the JSON data, its a program that you enter the varable & data then it will send it. SO I am not using java script or anything.
What It Sends Via Webhook

You have a lot of data in your payload that is not recognized by the Discord webhook. Allowed main tags are username, avatar_url, content, embeds, tts, file. So plain text can go to content, which in your case has worked successfully. Everything more fancy needs to be in the sub-content of embeds.
The best reference, I did found so far is this one.
I also suggest to preview your JSON-code in this tool.
So reduced to what works from your example, it is only this stuff:
{
"username": "Mason",
"avatar_url": "http://your.domain.here/a_bab14f271d565501444b2ca3be944b25",
"content": "Supa Hot",
"tts": false
}

Related

Why does this fetch request not work with the provided body

Following this documentation https://docs.tcgplayer.com/reference/catalog_getcategories
I have been able to generate a fetch request to get category search manifest from the endpoint. https://docs.tcgplayer.com/reference/catalog_getcategorysearchmanifest
However I am having trouble with this request https://docs.tcgplayer.com/reference/catalog_searchcategory
specifically the body portion. In my local project I am either getting an error "missing body" or when the body is attached "ops something when wrong" I believe that I am following all of the specifications provided in their documentation.
Here is a code snip of the working request and then one that I am having issues with, although the second request just seems to log and empty array in this environment. https://codesandbox.io/s/romantic-khorana-9tcez5?file=/src/App.js
I have been able to get https://docs.tcgplayer.com/reference/catalog_searchcategory to work with Thunderbolt Client vscode extension using this as a body
{
"sort": "ProductName ASC",
"limit": 500,
"offset": 0,
"filters": [
{
"name": "ProductName",
"values": ["Black"]
},
{
"name": "Rarity",
"values": ["T"]
}
]
}

How to access oauthIdToken returned from Firebase?

I'm trying to get the oauthIdToken of the result fetched from signing with firebase using signInWithCredential. I get the following back upon a successful login:
user Object {
"additionalUserInfo": bg {
"isNewUser": false,
"profile": Object {
"at_hash": "aWhmsdfeef32388EYD8YA",
"aud": "100423452193-gvmasfasdfasdfasfda7ee0.apps.googleusercontent.com",
"azp": "100406623293-gvmt0erkkob6asdfadfi7ee0.apps.googleusercontent.com",
"email": "fake#gmail.com",
"email_verified": true,
"exp": 1579142529,
"family_name": "last name",
"given_name": "first name",
"iat": 1579138929,
"iss": "https://accounts.google.com",
"locale": "en",
"name": "first last name",
"nonce": "Ow_sVcasdf50LdbHdTaro",
"picture": "https://lsfasfa.googleusercontent.com/-iKnasfasdf34/AAAAAAAAAAI/AAAAAAAAAAA/ACHi3re9asdfas7_Erg/s96-c/photo.jpg",
"sub": "100824234342680931658",
},
"providerId": "google.com",
},
"credential": Object {
"oauthAccessToken": "ya29.Il-5B47AOKYEQ5NYikv93gYyyhWu_2FEHEaadfaasfasdfasdfBVJCDXG3HJ9MdqalyyxvZ-6jMoqRsaGzhPUg6Cg862vF25xocHR6rnbh_-HuP2MMey4s59Gx8fXLwgQ99dQ",
"oauthIdToken": "eyJhbGciOiJSUzsdfagyZDgyMDQwM2VlODUxOGM0YWFiYjJiOWZlMzEwY2FjMTIiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291joiZW4iLCJpYXQiOjE1NzkxMzg5MjksImV4cCI6MTU3OTE0MjUyOX0.i-YiWbokasfiP_-xWCHJUyT_aLWp7eb3YCE6mzRUbbuKsdfsdfHptczrMXB5vMZY_5JFp8ZD2zxoNlvhTpuMY3B_zw_5Irk6HzuHGHXyAgzNJjh5n6cYR8gOiOsfsdfcKATpHcG7H_gOCwns_fI44I820qcmrogaEXuW-i3u9X5aXbTYqW5EaZQvQzuHkYHO2VWoktOTZsfsdfsfOaYYGU-tqW-ygAB_aWD7VPjIuUY4ySPF4k6IRR1x3ZysfdsdfdGGarX3isPGxMrDMtbRtsfsdfVaKsZdRtCpbfNUbFO8NR6x-pIvKsdfA",
"stsTokenManager": Object {
"accessToken": "eyJhbGciOiJSUzI1NiIsASDAFASFVmZTJlZDQyOWI3MzY0M2Y2NTEiLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoicmVudGVyaWkgcmVudGVyaGUuY29tIn19.n7z7HlL9lU7VEOA4fGIHvE9UMLSu5uo1rpfTm6m-N5A8CaKQaDu96sAvsG8iOVx8PYnytadffsafSRHyJoS0bzZbpQS6-YItdM5bIPxLMTFYEb0-Ho-tPnhRBSfWfPqJnK0c18YBFtHTG-0TvLNppmuZFG9AJjZZr0ASIkoOWmkI0gdOUAKBkutwMb3oitxeorT-pUdtKB5Rk23ekewz05oi7R5TI4xpBX5LsPvqaCqI4S5wxHe_BilRiiMhxd_lINdWftEkpctKSApJubML7mB9A",
"apiKey": "AIzaSysdfsdfsiWO7_2buk",
"expirationTime": 1579142530341,
"refreshToken": "AEu4IL01n_G6c4_Wg6fzseXRGPJHEAJnhzw7GLZVTS4RICikJ8PUgmmtNWXjcttOSbmYVCJDzGluUvTNKPHa4aS8gG0R3ijmrvPpcyJFPWZ5dRRDIlzxuoSyt70mewdRYgK4Eao7W21550slj7qHu8ZT_1bACJb31e_y7UnL2QjJEuvKwcWII8v8mgMPpYC2RH6fKg0Xrv9XLBgTxso25KfDrlfHBfYp4t35CzcVqODl71663_xV0WHhQ5gpv1hW0N39MMU5S0UEbQ_FnMmcJUFygaRvHndj2yNVhGwv_Re0uut3hUanPO_bo6OT4VEgIEEZ6cuiq8jzpH_T7d6bwI9eLZNS6IC1Fu8EJFmUWAtsdyBErq0s39gj2uta0uqLIGP_wlP5F_eDiw",
},
"tenantId": null,
"uid": "KlGB4adfadfn9ktr1",
},
Trying to access oauthIdToken with console.log(result.credential.oauthIdToken) inevitably provides null even though the variable is clearly present. I'm assuming this is similar to getting the accessToken within stsTokenManager where you can only get it using the method getIdToken() and credential.stsTokenManager.accessToken provides null.
How do I access oauthIdToken?
It took me a day to sort this one out. I was looking at using promises and found the answer by logging the parts of the object.
The output of printing out the result object is very confusing. The issue is that the JSON object representation has keys which don't correspond to the variables on the object. If you use console.log(JSON.stringify(result.credential)) rather than
console.log(JSON.stringify(result)) you will see the different variable names.
To see the OAuth Identity Token use console.log(console.log(result.credential.idToken)) without the oauth prefix. Likewise the access token doesn't have the oauth prefix.
It is important to know that in the Google/Firebase world there are two different types of identity token. The Firebase identity token is obtained from user.getIdToken(). It is sent to the server to allow the client to be verified. Its audience in the project identifier. The other type, which is the subject of the question, is the identity token generated by the Auth provider. If the Auth Provider is Google then this is the token you have to use to authenticate against Cloud Functions and Cloud Run services. The token needs to be sent in a Authorization: Bearer idtoken header on the request.

Facebook open graph doesn't return any instagram media

I have opened this as a bug with facebook here https://developers.facebook.com/bugs/105273653568982/
but thought I would ask here as well to see if anyone else has a solution:
The facebook open graph API says it is supposed to work for instagram as well as facebook, however when used from my server side code OR from the open graph explorer OR from postman, is only returning facebook media items, not instagram media items.
Eg a GET request for comments on my own facebook photo returns successfully:
Request:
https://developers.facebook.com/tools/explorer?method=GET&path=101205943227587%2Fcomments&version=v2.11&access_token=MYACCESSTOKEN
Result:
{
"data": [
{
"created_time": "2016-01-04T16:11:07+0000",
"message": "People might be abl",
"id": "101205943227587_1187008471313990"
}
],
"paging": {
"cursors": {
"before":"WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEU0TnpBd09EUTNNVE14TXprNU1Eb3hORFV4T1RJek9EWTQZD","after":"WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEU0TnpBd09EUTNNVE14TXprNU1Eb3hORFV4T1RJek9EWTQZD"
}
}
}
whereas endeavouring to get the same thing for an instagram post (again using my own media) doesn't work.
Request:
https://developers.facebook.com/tools/explorer?method=GET&path=1531969816055084767%2Fcomments&version=v2.11&access_token=MYACCESSTOKEN
Result:
{
"error": {
"message": "(#803) Some of the aliases you requested do not exist:
1531969816055084767",
"type": "OAuthException",
"code": 803,
"fbtrace_id": "D2xUM/kQWsJ"
}
}
None of the methods here
https://developers.facebook.com/docs/instagram-api/overview/
work for instagram media, eg attempting to get the info about Instagram's own account
GET graph.facebook.com
/25025320?fields=biography,id,username,website&access_token=MYACCESSTOKEN
returns an error
{
"error": {
"message": "Unsupported get request. Object with ID '25025320' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
"type": "GraphMethodException",
"code": 100,
"error_subcode": 33,
"fbtrace_id": "DCreoeyTARt"
}
}
My app has been approved to use the new api with the instagram_basic and instagram_manage_comments permissions, and I know the access token is valid as I am able to get facebook media and use the graph.facebook.com/me api so not sure why all instagram-related stuff is failing.

Cannot Send Mandrill Handlebars Template API

I am trying to access a Mandrill template which I made using their template builder in the Mandrill app (mandrillapp.com/templates).
As I read their documentation I am led to make an Ajax call as such:
{
"key": "<my api key>",
"template_name": "<my template name as defined in Mandrill templates>",
"template_content":[],
"message": {
"from_email": "<my from email>",
"to": <[an array of emails defined above]>,
"subject": "<my subject>",
"merge":true,
"global_merge_vars":[
{
"name": "visitorFirst",
"content": visitorFirst
},
"name": "visitorLast",
"content": visitorLast
},
{
"name": "visitorEmail",
"content": visitorEmail
}
]
}
This returns a 500 error. When I put the content inside "template_content" (which documentation says not to do for handlebars, it at least sends, but does not fill any of the merge variables. I have already set Mandrill to expect Handlebars, not Mailchimp variables.
What am I doing wrong?
Change
"template_content":[]
To
"template_content":null
Problem solved.

JavaScript request connection with data

I have a task to create javascript realtime app. Server side is ready (wss://), I have to create client-side.
The main tasks I have problems with:
The client can ping the server to check your connectivity. Client does a ping, including the sequence number (which allows to trace the exact ping duration).
{
"$type": "ping",
"seq": 1
}
server will respond:
{
"$type": "pong",
"seq": 1
}
Client request
{
"$type": "subscribe_tables"
}
Server will respond with the list of tables, and update the client with table_added, table_removed and table_updated messages whenever the status has changed.
{
"$type": "table_list",
"tables": [
{
"id": 1,
"name": "table 1",
"description" : "one, two"
}, {
"id": 2,
"name": "table 2"
"description" : "two, three"
}
]
}
table_updated event
{
"$type": "update_table",
"table": {
"id": 3,
"name": "table - Foo Fighters",
"participants": 4
}
}
Question: I know, that I can use new EventSource(), is this correct? How can I send data $type, for example with it?
I know, that I can use new EventSource(), is this correct? How can I
send data $type, for example with it?
No, that is not correct. If your server is expecting a webSocket connection, then you use new WebSocket(...) from the client to make the connection from client to server. And EventSource() object is used for server-side events which is a completely different transport from webSocket.
You can see programming examples here on MDN for using webSocket.
Also, if you are trying to send Javascript objects as data, you would typically use JSON.stringify() to serialize them into a string and then send that and then on the receiving end, you would use JSON.parse() to parse the JSON string back into a Javascript object. That's how you would send info like your $type along with other data in the same message.
FYI, socket.io is a library built on top of webSocket that has become very popular because it does a lot of things for your automatically that are typically needed in webSocket programming such as JSON serialization, automatic reconnect, automatic keep alive, connection drop detection, etc... You certainly don't have to use it in client and server, but it often saves a lot of time.

Categories

Resources