I want my bot to be able to send some replies later. Like in alarm clock, when user says, ping me at 5 AM then I want to send message to the user at 5 AM. How can I send message without receiving one?
You'll need to receive at least one message so that you know the recipient's address. You'll need to save the addressing info from the incoming message. I think the easiest way is to save the whole message.
Nodejs:
var reply = session.message; // address: reply.address
// ...
reply.text = 'Wake up!';
bot.send(reply);
C#:
var reply = activity.CreateReply(""); // reply.Recipient, reply.Conversation, etc.
// ...
reply.Text = "Wake up!";
ConnectorClient connector = new ConnectorClient(new Uri(reply.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
Without reply to an activity request, you can send a message to him like the following. I should mention that you must have the user's Id, and it means at least the user should have sent a message to the bot, to store his id.
string userId ="123456789"; // For Example
string serviceUrl = "https://telegram.botframework.com"; // For Example
var connector = new ConnectorClient(new Uri(serviceUrl));
IMessageActivity newMessage = Activity.CreateMessageActivity();
newMessage.Type = ActivityTypes.Message;
newMessage.From = new ChannelAccount("<BotId>", "<BotName>");
newMessage.Conversation = new ConversationAccount(false, userId);
newMessage.Recipient = new ChannelAccount(userId);
newMessage.Text = "<MessageText>";
await connector.Conversations.SendToConversationAsync((Activity)newMessage);
The above code comes from here.
Related
I have a requirement. I have a mail server where user sends mail with there requirement and i need to insert data in my database when mail arrive in mail box. i Have no idea about it. If anybody has any idea please share. Thanks in advance.
Please find the below codes for sending and receiving mails accordingly:
Send Mail
var message = new MailMessage("admin#bendytree.com", "someone#example.com");
message.Subject = "What Up, Dog?";
message.Body = "Why you gotta be all up in my grill?";`enter code here`
SmtpClient mailer = new SmtpClient("smtp.gmail.com", 587);
mailer.Credentials = new NetworkCredential("admin#bendytree.com","YourPasswordHere");
mailer.EnableSsl = true;
mailer.Send(message);
Recieving Mail
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("admin#bendytree.com", "YourPasswordHere");
var count = client.GetMessageCount();
Message message = client.GetMessage(count);
Console.WriteLine(message.Headers.Subject);
You can use this message object for database insertion.
I am trying to reply outlook email as we do manually it goes with previous conversations. But Below code is giving some error : Failed to send to the recipient address..I need to know how i can send it back to the person who sent me email..
import win32com.client, datetime
from datetime import timedelta
outlook =win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") # to trigger outlook application
inbox = outlook.GetDefaultFolder(6) # 6 is used for the index of the folder
messages = inbox.Items
message = messages.GetLast()# message is treated as each mail in for loop
for message in messages:
if message.Subject=="request": # based on the subject replying to email
#body_content = message.body
message.Reply()
message.Body = "shortly will be processed!!!"
message.Send()
The reply is a MailItem returned by reply(). So try this:
reply = message.Reply()
reply.Body = "shortly will be processed!!!"
reply.Send()
continuing to above answer
to reply all:
`rplyall=message.ReplyAll()`
to reflect previous conversations:
`rplyall.Body="your message here"+rplyall.Body()`
`rplyall.Send()`
Since MailItem.Body is a String and it is not callable. Reference document
I think the correct code in #Akhil 's answer is
rplyall.Body = "your message here" + rplyall.Body
rplyall.Send()
I have scheduling mail using 'send_at' with future time. Now I want to cancel that scheduled mail. How can achieve this problem. Please provide the solutions for it.
Thanks in advance.
Turns out that you can cancel scheduled email in sendgrid.
Here are the docs on how to do so
Mainly.. "Scheduled sends can be cancelled, if you include a batch ID with your send. "
The docs show you how to add the batch ID to your outbound messages so you can cancel them in the future.
As per the documentation, you cannot cancel scheduled messages at this time: https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html
This can be doable , by creating and assigning batchid in request
Create batch ID,
var batchId="";
var client = new SendGridClient(apikey);
var response = await client.RequestAsync(method:
SendGridClient.Method.POST, urlPath: "mail/batch");
if (response.StatusCode == HttpStatusCode.Created)
{
JObject joResponse = JObject.Parse(response.Body.ReadAsStringAsync().Result);
batchId = (((Newtonsoft.Json.Linq.JValue)joResponse["batch_id"]).Value).ToString();
}
return batchId;
Added batchId in Message body
var msg = new SendGridMessage()
{
From = new EmailAddress("youremail#abc.com", ""),
Subject = subject,
PlainTextContent = message,
HtmlContent = message,
BatchId=batchId
};
var offset = new DateTimeOffset(timeToSend.Value);
long sendAtUnixTime = offset.ToUnixTimeSeconds();
msg.SendAt = sendAtUnixTime;
msg.AddTo(new EmailAddress("recipientmail#abc.com"));
var response = await client.SendEmailAsync(msg);
3)Cancel a scheduled batch
var batchId="yur batch id"
var client = new SendGridClient(apiKey);
string data = "{\"batch_id\":\"" + batchId +"\",\"status\": \"cancel\"}";
var response = await client.RequestAsync(method: SendGridClient.Method.POST,
urlPath: "user/scheduled_sends", requestBody: data);
Note:
Make sure your api key has full access using sender grid option.
Setting --> apiKeys ---> edit Api key--> select "full access" and update
When a batch is canceled, all messages associated with that batch will stay in
your sending queue. When their send at value is reached, they will be discarded.
for more detail please refer enter link description here
Is it possible to import/export sms/mms on Blackberry10 programmatically using cascades API??
SMS actually uses the same API as other messages (like email). The key difference is that you want to pick the SMS account specifically, and you probably want to build is as part of a conversation.
Using the Message part of the BlackBerry PIM API, try something like this:
MessageService messageService;
AccountService accountService;
//Get the SMS/MMS account
QList<Account> accountList = accountService.accounts(Service::Messages,"sms-mms");
AccountKey accountId = accountList.first().id();
// Create a contact to whom you want to send sms/mms. Put the right phone number in yourself
int contactKey = -1;
MessageContact recipient = MessageContact(contactKey, MessageContact::To,"5555555555", "5555555555");
//Create a conversation because sms/mms chats most of the time is a conversation
ConversationBuilder* conversationBuilder = ConversationBuilder::create();
conversationBuilder->accountId(accountId);
QList<MessageContact> participants;
participants.append(recipient);
conversationBuilder->participants(participants);
Conversation conversation = *conversationBuilder;
ConversationKey conversationId = messageService.save(accountId, conversation);
//Create a message Builder for sms/mms
MessageBuilder* messageBuilder = MessageBuilder::create(accountId);
messageBuilder->addRecipient(recipient);
// SMS API's handle body as an attachment.
QString body = "body of the sms";
messageBuilder->addAttachment(Attachment("text/plain","body.txt",body));
messageBuilder->conversationId(conversationId);
Message message;
message = *messageBuilder;
//Sending SMS/MMS
MessageKey key = messageService.send(accountId, message);
qDebug() << "+++++++ Message sent" << endl;`
I'm trying to delete a user-to-user request using facebook-actionscript-api. So far no success..I've tried the following codes:
//try #1
var data:Object = new Object();
data.method = 'delete';
var userid:String = "idOfTheRequestSender"; //id of the request sender
var fullrequestID:String = requestId + '_'+ userid;//requestId - id of the sent request
Facebook.api(fullrequestID, onRequestDeleteCallBack, data, "POST");
//try #2
var userid:String = "idOfTheRequestSender"; //id of the request sender
var fullrequestID:String = requestId + '_'+ userid; //requestId - id of the sent request
Facebook.deleteObject(fullrequestID, onRequestDeleteCallBack);
I am replacing the userid with what it should be in my app.
Neither works as the callback function parameter is always null and the request is not deleted. Any help would be appreciated.Thanks.
The problem is just deleting the requests, i am able to send them.
EDIT:
The problem was that i was trying to delete the request from the Facebook account that sent the request, not from the account that received the request. Now it works. Thanks.
Did you try :
Facebook.api(fullrequestID, onRequestDeleteCallBack, {}, "DELETE");
Also are you getting any error messages?