I am wondering something.
In the XML file of a lightning message channel I can specify lightningMessageFields or I can omit this. Either way messages on the channel function correctly whatever you put into them.
Example one with no fields:
<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>TestChannel</masterLabel>
<isExposed>true</isExposed>
<description></description>
</LightningMessageChannel>
If i create a payload like this, it works:
let message = {request: true};
publish(this.context, TESTCHANNEL, message);
Example two with a field called 'success':
<LightningMessageChannel xmlns="http://soap.sforce.com/2006/04/metadata">
<masterLabel>TestChannel</masterLabel>
<isExposed>true</isExposed>
<description></description>
<lightningMessageFields>
<fieldName>success</fieldName>
<description></description>
</lightningMessageFields>
</LightningMessageChannel>
The same payload still works:
let message = {request: true};
publish(this.context, TESTCHANNEL, message);
So why bother with fields?
If any one has any insight into this, Id be very interested.
Thanks.
Dane
I like putting the messages there, but just for documentation, as you know it works either way. But if you need to remember the data that was supposed to be passed or received, then this will be very helpful.
Related
What I'm trying to achieve is simple:
send a message like links: [link1](https://example.com/1), [link1](https://example.com/2) via a bot
get it displayed as "links: link1, link1"
In a ephemeral follow up, it works as expected:
const content = "links: [link1](https://example.com/1), [link1](https://example.com/2)"
await interaction.followUp({
ephemeral: true,
content,
})
But when I send this to a public channel like this:
await channel.send(content)
I'm getting it as plain text (links: [link1](https://example.com/1), [link1](https://example.com/2)) except the links are clickable.
Is it possible to get the same result as in an ephemeral message?
I've checked the permissions, there's only "embed" links (which sounds like "allow links in embeds", and not "allow links in messages) and it is enabled anyway on server for everyone, for the bot and in the channel. So what am I missing here?
PS Here they say that "it's only possible if the message was sent with webhook though", but I'm not quite sure what does this mean (can this be different for a public and an ephemeral message?)
You cannot use hyper links in normal messages sent by a bot. You need to use a Webhook. Considering you're using discord.js, see this guide on their documentation. When using something like that it will work as expected
const { WebhookClient } = require('discord.js');
const webhookClient = new WebhookClient({ url: "WEBHOOK_URL" });
webhookClient.send({
content: "[Hello world](https://github.com)",
username: "Webhook Username",
});
Otherwise you may use embeds and send one of these with your bot and the content you wish to have.
Right, so I've found a solution based on suggestion by Krypton. As an embed doesn't look nice and manual creation of a webhook is not an option for me, I've found that I can create a webhook on the go and use it.
After some testing, I've figured that such webhooks are also permanent (although they can be found in another part of settings than the manually created ones); they should be deleted as there's a limit of 15 webhooks – an attempt to create more fails (with DiscordAPIError[30007]: Maximum number of webhooks reached (15)).
Instead of doing
await channel.send(content)
I've put
// a guard, TypeScript requires us to be sure
if(channel instanceof TextChannel) {
const webhook = await channel.createWebhook({
// a message from a webhook has a different sender, here we set its name,
// for instance the same as the name of our bot (likewise, we can set an avatar)
name: "MyBot",
})
await webhook.send(content)
await webhook.delete()
}
This seems to be a minimal code change to get the links working.
I have coded a bot to send a message response to a given command, !a. I want to store additional data on the message object, so that if the user reacts to that message the bot can read the hidden data property and know the original message resulted from !a.
Ideas I had:
Create a custom property on the message object: Message.Custom_Prop
Hijack an unused property: Maybe Message.webhookId?
Store hidden text in the form of an embed or message content.
I haven't been able to get any of these to work though.
The best way that I can think of is to store an array of message IDs that were triggered by !a. Something like this:
// At the start of your script
const commandResponses = [];
// Logic for sending the command response
message.channel.send("response here").then(msg => commandResponses.push(msg.id));
// Checking whether the message was a response
if (commandResponses.includes(reaction.message.id)) {
// It's a response so do stuff here
}
(Not tested so it's possible that this won't work)
I have this command called p!slap and I want it so that my bot will say {message.author} slapped {message.mention} and a random gif but I have no idea how to. Can anyone help? Thanks!
#client.command()
async def slap(ctx, message.mention):
embedVar = discord.embed(title=f"<#{message.author.id}> slapped {message.mention}")
list = [
#gif links and stuff
]
await ctx.channel.send(random.choice(list))```
Your code has a few problems.
At first, I couldn't understand what you're trying to do with naming a parameter message.mention but I guess what you're trying to do is "slapping" the person you mentioned in command. For that, you have to get the member object in parameter. Then, you can mention this member.
Also, you shouldn't define a variable named list. This might cause a error because of the built-in method list.
An another thing is, there's no embed method for discord module, it must be discord.Embed. You have to pay attention to the uppercase letters.
You never sent the embed you defined, you must send it for your command to work.
For the last one, I don't know what'll be in the list lst but I guess there will be files. If you're going to send a file, you cannot just send it. You have to pass a parameter in .send() method. But this is only for the files. If you're just going to send a link, then you don't have to pass any parameters.
#client.command()
async def slap(ctx, member: discord.Member):
embedVar = discord.Embed(title=f"{ctx.author.mention} slapped {member.mention}")
lst = [
#gif links and stuff
]
await ctx.channel.send(file=discord.File(random.choice(lst)), embed=embedVar)
I've created a custom transport for CakeEmail (to allow me to use Mandrill to send email). However, whenever I access the content of the message (which is cake email template driven), it doesn't encode the characters correctly (it changes 'é' to 'é', etc). If I use CakeEmail and bypass the transport, it displays the characters correctly in the email. I've narrowed this down to $email->message('html') in the transport code. If I output $email->message('html'), the characters are already incorrect.
App::uses('AbstractTransport', 'Network/Email');
App::uses('HttpSocket', 'Network/Http');
class MandrillTransport extends AbstractTransport {
public function send(CakeEmail $email) {
debug($email->message('html'));exit;
}
}
Thoughts?
You most probably have an encoding mismatch somewhere, if for example your App.encoding doesn't match your CakeEmail::$charset, CakeEmail would try to convert the content from App.encoding to CakeEmail::$charset.
https://github.com/cakephp/.../2.6.2/lib/Cake/Network/Email/CakeEmail.php#L1338
If for example the former were iso-8859-1, and the latter utf-8, just like the content, you would end up with the result you are showing here.
// outputs é when displayed as utf-8/unicode
echo mb_convert_encoding('é', 'utf-8', 'iso-8859-1');
You'll have to do some further debugging to trace down where exactly things are going wrong.
I'm having trouble getting more than just the snippet for text data for the message I am trying to retrieve using the Gmail API. Here is the piece of test code I am working with:
public string GetMail()
{
GmailService service = (GmailService)HttpContext.Current.Session["service"];
Message messageFeed = service.Users.Messages.List("me").Execute().Messages.First();
UsersResource.MessagesResource.GetRequest getReq = new UsersResource.MessagesResource.GetRequest(service, "me", messageFeed.Id);
getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Full;
Message message = getReq.Execute();
return message.Raw;
}
For some reason, when I call message.Raw, it is returning null. I am able to retrieve other properties as what the format=minimal setting would based off of the API playground example I was playing with.
However in my code, I am setting the format enum to "full", yet I am still unable to retrieve the full data of the message.
Am I completely missing something here?
Seems like you're mixing up formats and response types. If you want the raw message as a string in Message.raw then you need to set:
getReq.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
If you want the parsed message back (in the "payload" field) then you can use getReq.Format of Full like you have.
Acceptable values are:
"full": Returns the parsed email message content in the payload field and the raw field is not used. (default)
"minimal": Only returns email message metadata such as identifiers and labels, it does not return the email headers, body, or payload.
"raw": Returns the entire email message content in the raw field as a string and the payload field is not used. This includes the identifiers, labels, metadata, MIME structure, and small body parts (typically less than 2KB).
from: https://developers.google.com/gmail/api/v1/reference/users/messages/get