I am not getting how to send image to any number using WhatsApiNet ?
case "/image":
byte[] imgData = File.ReadAllBytes(#"d:\My Creations\DSC_0423 copy.jpg");
wa.SendMessageImage(tmpUser.GetFullJid(), imgData, ApiBase.ImageType.JPEG);
break;!
But its not working..
I too was facing the same problem, fortunately I got the solution :)
byte[] img = File.ReadAllBytes("e:\\img.gif");
wa.OnConnectSuccess += () =>
{
MessageBox.Show("Connected to whatsapp...");
wa.OnLoginSuccess += (phoneNumber, data) =>
{
wa.SendMessage(to, msg);
wa.SendMessageImage(to + "#s.whatsapp.net",img,ApiBase.ImageType.GIF);
MessageBox.Show("Message Sent...");
};
}
You will just need to modify only 1 line in your code.
wa.SendMessageImage(tmpUser.GetFullJid()+ "#s.whatsapp.net", imgData, ApiBase.ImageType.JPEG);
Hop this will help others too :D Hav a Nyc day :)
See: Is it legal to use WhatsAPI?
There seems to be an indication of ongoing legal issues between WhatsApp and the creator of the API open-source project.
There's also mention that WhatsApp have changed some of the details around authentication, so it may be the case that you can't send the message simply because WhatsApp have stopped allowing access.
Related
I'm trying to code a chat-log function into my bot. I know of IMessage.Attachments, but I don't know how to actually use it.
I don't have my exact code on hand (for now), but it looks like this:
_client.MessageReceived += async (message) =>
{
var attach = message.Attachments.Url as IMessage; //get Url of attachment
if ('message contains attachment (?)' && !message.Author.IsBot)
await message.Channel.SendMessageAsync("Attachment: " + attach); //send attachment
};
Of course, that doesn't work. The documentation didn't really help me either. It would be nice if someone could explain this to me.
Got it to work with this:
message.Attachments.FirstOrDefault().Url
My Xamarin app for Android reads some local data, process them and returns the results as a string like:
"Current target is X, please increase power to Y".
I want to have a button in my app that will open the usual sshare command that we see in many applications and where it is possible to say that the content will be shared with the apps that you have on your phone.
For example if I use WeChat or even WhatsApp I can click on that icon and select the contact to share my string.
How can I achieve this in Xamarin. In particular, I would need to interact with WeChat, WhatsApp and Facebook.
I want to have a button in my app that will open the usual sshare command that we see in many applications and where it is possible to say that the content will be shared with the apps that you have on your phone.
You can refer to the official doc: Sending Simple Data to Other Apps for Android, in Xamarin.Android, it's similar, for example:
Intent intentsend = new Intent();
intentsend.SetAction(Intent.ActionSend);
intentsend.PutExtra(Intent.ExtraText, "Current target is X, please increase power to Y");
intentsend.SetType("text/plain");
StartActivity(intentsend);
I personally have not tried that as I do not need it this far. However, I found this Xamarin.Social package and probably sharing to you is helpful. Here is the example at their GitHub repo. I will attach the code snippet from their example so it is easier to you to read here.
//taken from https://github.com/xamarin/Xamarin.Social/blob/master/samples/Xamarin.Social.Sample.Android/MainActivity.cs
void Share (Service service, Button shareButton)
{
Item item = new Item {
Text = "I'm sharing great things using Xamarin!",
Links = new List<Uri> {
new Uri ("http://xamarin.com"),
},
};
Intent intent = service.GetShareUI (this, item, shareResult => {
shareButton.Text = service.Title + " shared: " + shareResult;
});
StartActivity (intent);
}
public override void OnCreate(Bundle bundle)
{
...
facebookButton.Click += (sender, args) =>
{
try
{
Share (Facebook, facebookButton);
}
catch (Exception ex)
{
ShowMessage("Facebook: " + ex.Message);
}
};
...
}
Hope this could help.
I want to be able to reply to an email inline, from within my program, but calling the reply function seems to only fill in the To: and Subject: field for me. I can't seem to find anything online about it and it doesn't seem to have an overload that turns on inline replies.
I found that each MailItem has a Conversation so I'm wondering if I have to manually do the inline reply? (I would really like to avoid that, it would be a pain to iterate through a conversation, some of ours can be hundreds of emails long).
I found that this code helped make this happen;
Document oldDoc = itemToReplyTo.GetInspector.WordEditor;
Document newDoc = newMailItem.GetInspector.WordEditor;
if (oldDoc != null)
{
Microsoft.Office.Interop.Word.Selection oldSelect = oldDoc.Windows[1].Selection;
Microsoft.Office.Interop.Word.Selection newSelect = newDoc.Windows[1].Selection;
oldSelect.Find.Execute("From:");
oldSelect.Collapse(WdCollapseDirection.wdCollapseStart);
oldSelect.MoveEnd(WdUnits.wdStory, 1);
oldSelect.Copy();
newSelect.Move(WdUnits.wdStory, 1);
newSelect.InlineShapes.AddHorizontalLineStandard();
newSelect.Paste();
newSelect.Move(WdUnits.wdStory, -1);
newSelect.InsertAfter("Reply Text here");
newSelect.Find.ClearFormatting();
newSelect.Find.Execute(mailItem.SenderEmailAddress);
}
I tried the below and it worked for me using Outlook 2010.
Outlook.MailItem reply1 = mailItem.Reply();
//prepend text to email
reply1.HTMLBody = "<html><body><strong>Test Body</strong><p><p></body></html>" + reply1.HTMLBody;
reply1.Display(false); //display message or .Send() to send
I have been working on an IMAP client to get emails from Gmail. My application worked fine until about an hour ago, when attachments stopped being retrieved.
The connection and messaging is being handled by imapX.
Connection is OKAY
Login is OKAY
Getting folders is OKAY
Getting messages is OKAY
At this point attachments.Count == 0. It was working earlier this afternoon so I wonder if I have been over testing and Google have blacklisted my computer for a while? Does anyone know if this is the case? - Been running perhaps once every 5-10 minutes, maybe more at times so this could be a plausible issue.
I have attempted to send a new email with a totally new file and it still does not see the attachment (but it is (always) seeing the messages themselves).
Can any anyone shine some light on this issue?
EDIT : Header includes the following tag {[X-MS-Has-Attach, yes]}
EDIT (code) :
private void PollMailFolders(object state)
{
try
{
if(_imapClient == null || !_imapClient.IsConnected)
_imapClient = new ImapClient(_config.Server, _config.Port, true);
if (_imapClient.Connection())
{
if(!_imapClient.IsLogined)
_imapClient.LogIn(_config.Username, _config.Password);
string dateSearch = string.Format(
"SINCE {0:d-MMM-yyyy}{1}", DateTime.Today.AddDays(-_config.HistoryOnStartupDays),
_isFirstTime ? "" : " UNSEEN");
_isFirstTime = false;
foreach (Folder folder in _imapClient.Folders["SSForecasts"].SubFolder)
{
var messages = _imapClient.Folders[folder.Name].Search(dateSearch, false);
foreach (Message m in messages)
{
m.Process();
foreach (var a in m.Attachments)
{
SendDataToParser(_encoding.GetString(a.FileData), folder.Name);
}
m.SetFlag(ImapFlags.SEEN);
}
}
}
}
catch(Exception e)
{
_diagnostics.Logger.ErrorFormat("Error in PollMailFolders: {0}", e);
}
}
I have produced a work around which allows me to get the attachment data. Not the solution I had in mind, though it does work.
Simple filename extension check followed by a conversion of the message data.
BTW: _encoding = Encoding.GetEncoding(1252);
if (bodyPart.ContentFilename.EndsWith(".csv"))
{
return _encoding.GetString(Convert.FromBase64String(bodyPart.ContentStream));
}
I have been working with Monodroid for a few days and still can't figure out how to send a command through Bluetooth.
This is my scenario: I have a Tablet/Cellphone working with Android 2.1+ and need to send and receive data to a Bluetooth printer (in bytes).
What i managed so far:
using Android.Bluetooth; // library necessary
BluetoothAdapter bth = BluetoothAdapter.DefaultAdapter;
if (!bth.IsEnabled)
bth.Enable();
ICollection<BluetoothDevice> bthD = bth.BondedDevices;
foreach (BluetoothDevice d in bthD)
{
if (d.Name == "DPP-350")
{
Java.Util.UUID UUID = Java.Util.UUID.FromString("00001101-0000-1000-8000-00805F9B34FB");
// Get the BLuetoothDevice object
BluetoothSocket s = d.CreateRfcommSocketToServiceRecord(UUID);
s.Connect();
// Try to send command
...
s.Close()
}
}
The program asks for the pairing info, with is done correctly.
I have tried many ways to send the command:
// the command
// Self_Test = Chr(27) + Chr(84) = ESC T
byte[] dBytes = System.Text.Encoding.GetEncoding(1252).GetBytes(Self_Test);
// wont work
new Java.IO.ObjectOutputStream(s.OutputStream).Write(dBytes);
// wont work
System.IO.Stream st = s.OutputStream;
if (st.CanWrite)
{
st.Write(dBytes, 0, dBytes.Length);
st.Flush();
}
// wonk work
s.OutputStream.Write(dBytes, 0, dBytes.Length);
s.OutputStream.Flush();
No error is raised. I'm running out of options here...
Thanks in advance!
I know this is a very old thread, but I wanted to post a reply so others will know the answer. I too searched hard with no luck.
s.OutputStream.BeginWrite(buffer, 0, buffer.Length,new AsyncCallback(delegate {}), State.Connected);
Thanks.