DSharpPlus send an embed to a specific channel? - c#

I'm new to working with discord bots and I was wondering if anybody knew a way to send embedded messages to specific channels. The only way I've found so far to send one is to use RespondAsync which just directly replies to whoever issues the command in the same channel. The purpose of my bot is to create automated link directories in read only channels and the command will just refresh them. Having trouble finding much Dsharpplus c# examples, and I'm terrible at making sense of documentation. Any help would be appreciated.
await ctx.RespondAsync(embed);
this is what I've been using to send my embeds for testing purposes, but like I said I'd like to send it in a way that it posts to a specified channel

You just need to get the DiscordChannel object of the channel(s) you want to send the embed. You can get the ID of the channel via right-click in Discord and "Copy ID"
DiscordChannel channel = await _client.GetChannelAsync(ID_OF_CHANNEL);
DiscordEmbedBuilder embed = new DiscordEmbedBuilder
{
Color = DiscordColor.SpringGreen,
Description = "Good to see you!",
Title = "Hello World"
};
await channel.SendMessageAsync(embed: embed);
The DiscordGuild class also has GetChannelAsync you can use.

Related

Telegram Bot API C# How to get All Pinned Messages?

Telegram added the feature to pin more than one message. I'm doing it like this:
var chat = botClient.GetChatAsync(chatid).Result;
pinnedmsgtxt = chat.PinnedMessage.Text;
pinnedmsg= chat.PinnedMessage;
but I can only get the last message that was pinned. Any way to get all of them? Am I missing something? I'm using https://github.com/TelegramBots/telegram.bot
Use messages.search method with inputMessagesFilterPinned filter.
Please read more here:
Pin API
Message Search API
Pinned messages filter

Check if user ID exists in Discord server in c#

I'm trying to make a auth link that the user will open then to get the client id from the user and check if the user is exists in a server. I'm not sure what lib should I use would love to get help thank you. I saw this code but this is in JavaScript and I need it in c# + the part of auth link
USER_ID = '123123123';
if (guild.member(USER_ID)) {
// there is a GuildMember with that ID
}```
DSharpPlus is a fairly simple library to use. It'll throw 404 not found when the user isn't found so you'll need to check the ClientErrored event for failure.
var guild = //get current guild somehow
var user = await guild.GetMemberAsync(USERID);
Documentation on GetMemberAsync: https://dsharpplus.emzi0767.com/api/DSharpPlus.Entities.DiscordGuild.html#DSharpPlus_Entities_DiscordGuild_GetMemberAsync_System_UInt64_
Repo: https://github.com/DSharpPlus/DSharpPlus
D#+ vs Discord.Net is DNet will give you more control over handling of events and messages. D#+ is more plug and play kind of deal.

How to setup buttons with "imBack" type in Slack channel using ms bot builder

I've developed few bots using ms botbuilder, there was no problems with Buttons with "imBack" type on Skype, FB, Telegram and web chat.
However trying to make it work on Slack i found (and seems like its not documented) that you need extra configuring of Interactive Messages in APP admin panel. So here's my questions regarding this issue:
is it true that its the only way?
If so what's the real reason for that, everything works just fine in all other channels.
Is there a way to setup it programmatically, cos it will be real bad for distribution of bot?
even when i setup endpoint in admin panel looks like it makes request that is barely compatible with how ms builder works (it sends some GET where we need post with relevant info)
Code sample:
...
var reply = activity.CreateReply("hi, can i ask you few question?");
reply.Attachments = new List<Attachment>(){};
var buttonSelect = new CardAction
{
Value = $" /startCommand",
Type = "imBack",
Title = "ok, ask me"
};
var cardForButton = new ThumbnailCard { Buttons = new List<CardAction> { buttonSelect } };
reply.Attachments.Add(cardForButton.ToAttachment());
await connector.Conversations.CreateDirectConversationAsync(botaccount, userAccount, reply);
...
2 things you can try that are possible solutions
You probably did, but did you activate interactive messages in your slack api dashboard?
There is a token (Verification Token) that you need to get from the oauth section of the Slack api site for your app. you need to include that with the other information here https://slack.botframework.com/Dev/?botId={yourBotID}
Actually all needed to be done is put https://slack.botframework.com/api/Actions in Request URL when enabling Interactive Messages in Slack, not sure that it was documented earlier on Ms bot framework panel, but it is now. Issue resolved.

Ionic sending Parse push notification with attached url

I've been busy with a new application based on ionic. It's a new environment so I have a lot to explore.
I'd walked into some problems and search over the whole internet to find a solution and couldn't find one solving my problem. So I hope one of you guys know a solution.
I am trying to send notifications to my device using parse. That works fine, but now I want to send an uri attached with it, so that I can open a specific page clicking on the notification that has been recievied.
The problem is that I have no clue how to correctly send an attached uri and recieve that uri on the device to do something with it.
I hope some of you knows a solution.
I'm using ASP.NET to send the notification with a working initialized client.
var parsePush = new ParsePush();
// sending to all with your own data
parsePush.Data = new Dictionary<string, object>
{
{"alert", txtMessage.Text},// this is replacement for parsePush.Alert
{"sound", "notify.caf"},// for ios
{"badge", "Increment"}// for ios notification count increment on icon
//{"category", "http://google.nl" }
};
parsePush.SendAsync().Wait();
For the ionic side I don't have an event to recieve the notification and work with it. I just get the notification and get redirected to the home page of the app.
Please inform me if there are unclear details.
Thanks a lot!
I fixed this problem by searching over the whole internet.
The first thing I did was uncommenthing the category in my parsePush.data on the server side (see code in the question). In the category I define the uri. The next thing I did was adding "ParsePushPlugin.on" to my app.js. Those event are used when a notification is recieved or opened.
I added this code to my app.js inside the .run -> $ionicPlatform.ready.
ParsePushPlugin.getInstallationId(function (id) {
alert(id);
storage.set('parseId', id);
}, function (e) {
alert('error');
});
ParsePushPlugin.on('receivePN', function (pn) {
alert('yo i got this push notification:' + JSON.stringify(pn));
});
//customEvt can be any string of your choosing, i.e., chat, system, upvote, etc.
ParsePushPlugin.on('receivePN:chat', function (pn) {
alert('yo i can also use custom event to keep things like chat modularized');
});
ParsePushPlugin.on('openPN', function (pn) {
//you can do things like navigating to a different view here
//alert('Yo, I get this when the user clicks open a notification from the tray');
$state.go(pn.category)
});
As you can see "ParsePushPlugin.on('openPn')" has pn as parameters which contains all the data from the recieved and opened notification. This notification also contains the "category (uri)" which is passed from the server side.

Selenium Webdriver automation with emails

I'm currently trying to use Selenium Webdriver (C#) to automate a Forgot Password -> Reset Password workflow, where the user navigates to a page and supplies their username, and the backend code validates the username, then sends an email with a reset password link to the email address associated with their account.
I'm able to automate the process up to the point where the code sends the email, but I don't know any ways of checking for the email and/or clicking a link in the email, so I was hoping someone more experienced with Selenium/automation may be able to give me a few pointers.
Ideally the test should not care about the email address that the email is being sent to. Is there a way for Selenium WebDriver or some 3rd party package to catch the email being sent?
Thanks for any input or suggestions.
No. You are talking about setting up an email server, which is not an easy task.
You should send it to a test work email (if this is for a company), or a public email (hotmail/gmail), or if security is not an issue at all, the easiest place to send it would be a disposable email (mailinator)
You could try PutsBox. You can send an email to whatever-you-want#putsbox.com, wait for a few seconds (SMTP stuff ins't instantaneous) then check your email via http://preview.putsbox.com/p/whatever-you-want/last.
Have a look at this post tutorial, it can give you some ideas.
There is no integration of selenium with email clients like Thunderbird/Outlook. But if you have a web interface of the same email client, then you can access the email from browser and using selenium you can read and respond to the emails. I have tried this recently and it works fine where I have used web Outlook for testing.
Hope this helps.
Hi I was in a similar situation and was able to successfully implement a way to get an activation or forgotten password links.
Using Java Mail API I was able to trigger a method when such action is performed which goes into a Folder and read a specific message line then get the link and open it up in a browser using WebDriver.
However the main drawback with this is the inconsistency of reading a specific folder, sometimes emails goes to spam or other folder (in case of Gmail the new Social Folder) making it invisible or difficult to be retrieved.
Overall i think its a process that shouldn't really be automated, In terms of testing it should be done more code base level by mocking responses.
Snippet below should give you an idea on how to go about implementing
public class RefactoredMail {
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getInstance(props, null);
Store store = session.getStore();
store.connect("imap.gmail.com", "username", "password");
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);
Message msg = inbox.getMessage(inbox.getMessageCount());
Address[] in = msg.getFrom();
for (Address address : in) {
System.out.println("FROM:" + address.toString());
}
Multipart mp = (Multipart) msg.getContent();
BodyPart bp = mp.getBodyPart(0);
System.out.println("SENT DATE:" + msg.getSentDate());
System.out.println("SUBJECT:" + msg.getSubject());
System.out.println("CONTENT:" + bp.getContent());
System.out.println("Activation Link:" + ((String)
bp.getContent()).startsWith("http"));
String [] line = new String[1];
line [0] = mp.getContentType().toString();
System.out.println("Activation Link:" + (mp.getBodyPart(0).getLineCount()));
System.out.println("Activation Link:" +line[0]);
} catch (Exception e) {
e.printStackTrace();
}
//WebDriver Stuffs
public String activationUrl() {
//getting the url link and making it a global variable .... etc
//Accessing the link
}
}
You can use https://github.com/cmendible/netDumbster or http://ndumbster.sourceforge.net/default.html. I've used one i forget which. This will host an smtp listener and allow you to make assertions against any email it receives. Its kind of awesome! The caveat is you need to be able to control where the server delivers mail in the environment you are testing.

Categories