I'm trying to make telegram bot using talegram.bot library and i have a question about user messages: how can i make receiving message from user only after some text from bot? Here is example from BotFather
e.g. if user send message to bot-bot ignores the message text and responses like that, but if
user clicks on InlineKeyboardButton, bot sending to user message like "write your text", bot recieves that text and saves
I suggest to you use Telegram.dll library if you are a C# programmer and easily Define a sample IF operation like below code . you can control every thing if use the DLL file .
String Token = "399684XXX:AAH_NiVFXXXXX";
int ID=0;
while (true)
{
bot.update = "true";
ID = bot.chat_id;
if (bot.message_text=="/contact-us"){
bot.sendMessage.send(ID, "Email:name#website.com" + "\n" + "Website: www.website.com");
}
if (bot.message_text=="/apple")
{
bot.sendMessage.send(ID, "lap lap lap...");
}
else
{
bot.sendMessage.send(ID, "/contact-us" + "\n" + "/apple");
}
}
Related
Can we check whether the input form in an adaptive card is filled or not with a warning message.
I am currently using an adaptive card to gather user input in bot application,I have already added isRequired for input validation but it doesnot give any warning message instead when I click on submit it doesnot go to the next method.
As soon as the user presses submit I want to make sure that the form is not empty
If you have an Adaptive Card like this (notice the ID given to the input):
var card = new AdaptiveCard
{
Body =
{
new AdaptiveTextBlock("Adaptive Card"),
new AdaptiveTextInput { Id = "text" },
},
Actions = {
new AdaptiveSubmitAction { Title = "Submit" } },
},
};
You can validate the value sent through the submit action like this:
if (string.IsNullOrEmpty(turnContext.Activity.Text))
{
dynamic value = turnContext.Activity.Value;
string text = value["text"]; // The property will be named after your input's ID
var emailRegex = new Regex(#"^\S+#\S+$"); // This is VERY basic email Regex. You might want something different.
if (emailRegex.IsMatch(text))
{
await turnContext.SendActivityAsync($"I think {text} is a valid email address");
}
else
{
await turnContext.SendActivityAsync($"I don't think {text} is a valid email address");
}
}
Validating email with regex can get very complicated and I've taken a simple approach. You can read more about email Regex here: How to validate an email address using a regular expression?
I took totally different approach than the accepted answer here. If you are going to use adaptive cards a lot in your bot than it makes sense to create card models and have validation attributes applied to each field that needs validation. Create custom card prompt inheriting from Prompt<object> class. Override OnPromptAsync and OnRecognizeAsync and check the validation of each field there.
So i need to get informations such as :
Sender mail address (to later get his Domain profile informations)
Mail subject (which should be the "filepath" minus the "msg" extension anyway).
And then, replying to it just like i would push "ReplyAll" button in Outlook. So the reply needs to get the usual Headers such as "From : ....", "To : ...", "Cc : ..." and so on.
All i need is to change its subject, and delete the address depending on the "FromAddress" of the user that will push the button
I've read a bit here and there, and people are talking about a MailItem, but there's no informations about HOW to get this item or how to build it from a .msg file.
What i have to do comes after a specific user action.
The user is supposed to Drag&Drop the mail into a panel, from there i get its local path.
Thanks for your time !
Edit#1
I managed to find out to get informations and to set a .msg file to a MailItem :
Outlook.Application appOutlook = new Outlook.Application();
var email = (Outlook.MailItem)appOutlook.Session.OpenSharedItem(filepath);
string getCC = "";
string getFrom = ""; // From is never null
string getTo = "";
string getSubject = "";
bool lengthCC = email.CC.HasValue();
bool lengthTo = email.To.HasValue();
bool lengthSubject = email.Subject.HasValue();
if (lengthCC)
{
getCC = email.CC.ToString();
}
// and so on...
//
// Display it in MessageBox to confirm test succeeded :
MessageBox.Show("CC : " + getCC +
"\nFrom : " + getFrom +
"\nTo : " + getTo +
"\nSubject : " + getSubject);
email.Close(Outlook.OlInspectorClose.olDiscard);
Now i just need to build the ReplyAll Body and add headers manually myself i guess...
Edit#2
No need to rewrite Headers apparently, doing so :
Outlook._MailItem reply = email.ReplyAll();
reply.To = getFrom;
reply.CC = getCC;
reply.Body = "SomeReplyMessage" + reply.Body;
reply.Send();
Marshal.ReleaseComObject(appOutlook);
Marshal.ReleaseComObject(email);
Marshal.ReleaseComObject(reply);
But it erased the separator above the original message, i'll find a way to re-add it !!!
Edit#3
And there it is, the so-called "separator" wasn't displaying, because i wasn't re-stating an HTML Body !
So, to keep it you can do this :
reply.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
string ReplyMessageBody = String.Format("AddSome<br>HTMLCode<br>ThereAndHere<br>ButFinishWith : BodyTag</body>");
reply.HTMLBody = ReplyMessageBody + reply.HTMLBody;
Or simpler if you don't need your reply to be an HTML one :
reply.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
reply.HTMLBody = "AddSomeReplyMessage" + reply.HTMLBody;
Outlook does not work directly wit MSG files - when you call CreateFromTemplate or even OpenSharedItem, Outlook creates a new item in its default store and imports the MSG or OFT file. It does not expose anything that would you let you figure out that the message came from a file; the item is indistinguishable from an item created directly using CreateItem or MAPIFolder.Items.Add.
See edits on original question for answer !
i'm trying to send message to People user name for example my friends username is #...
but no thing happend
no Error
and no send
can i use this library ?
or just with tlsharp?
how can i found apiid and hashid for my bot?
using Telegram.Bot;
and
public partial class Form1 : Form
{
Telegram.Bot. TelegramBotClient bot = new TelegramBotClient("token");
Thread a;
public Form1()
{
InitializeComponent();
}
public void GetUpdates()
{
int offset = 0;
while (true)
{
Telegram.Bot.Types.Update[] updates =
bot.GetUpdatesAsync(offset).Result;
foreach (var update in updates)
{
offset = update.Id + 1;
if (update.Message == null)
continue;
var from = update.Message.From.FirstName;
var text = update.Message.Text;
string chatid = update.Message.Chat.Id;
string username = update.Message.From.Username;
// label1.BeginInvoke(delegate { label1.Text = label1.BeginInvoke(delegate { label1.Text = string.Format("sender:{0}\ntext:{1}\ncatid:{2}", from, text, chatid); }); });
// lblshow.Text = string.Format("sender:{0}\ntext:{1}\ncatid:{2}", from, text, chatid);
//label1.Text = string.Format("sender:{0}\ntext:{1}\ncatid:{2}", from, text, chatid);
this.BeginInvoke((System.Windows.Forms.MethodInvoker)delegate () {textBox1.Text = string.Format("sender:{0}\ntext:{1}\ncusername:{2}", from, text, username); });
bot.SendTextMessageAsync( chatid, "سلام بر شما");
//is this correct for send to people?
bot.SendTextMessageAsync("#Hoda.....", "hi");
}
}
you cant send message to user by user Name.telegram bot API only accept user Id. (except channels).
When you try to send messages to users you must know their chatID (chatID is a long number which is unique for every user in telegram and never changes while username can be changed) or you must have stored their chatIDs in a database or a file or ...
This means a user must have sent at least one message to your bot before this includes the /start command. Then your bot can find out their chatID and using that chatID, you can send whatever you want to that user unless he/she has blocked your bot by pressing Delete and Stop button when trying to delete the conversation between him/her and your bot.
You can but don't pass # symbol, If the username is #me pass "me" to SendTextMessageAsync without passing #.
How to retrieve email based on time in Google api using c#?
Can we pass date time to query string for getting the latest email?
While working around this one i am able to find pas the date only.
Is there any way to get the latest mail based on time?
Yes, you can achieve this by passing in a query parameter along with Get Message List call of Gmail API like below:
List<Message> result = new List<Message>();
UsersResource.MessagesResource.ListRequest request = service.Users.Messages.List(userId);
request.Q = query;//This is where you put in your data query
do
{
try
{
ListMessagesResponse response = request.Execute();
result.AddRange(response.Messages);
request.PageToken = response.NextPageToken;
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
} while (!String.IsNullOrEmpty(request.PageToken));
Query parameter is the same as you pass in your mailbox search box. e.g. after:2015/6/28 before:2015/7/1
Afterwards, fetch individual message details by calling Get with message ID.
Hope this helps.
Furhan's answer is great. I would just like to add, that if you want to search for mails more specifically than 2015/6/28, you can supply e.g. after:<TIME_IN_SECONDS_SINCE_EPOCH>
Let's say you wanted mail after:2015/6/28 12:55:00 and before:2015/7/1 02:30:00, your would write:
after:1435496100 before:1435710600
I want to send SMS programatically for that i am using below code but seems that it dontwork in 8.1
SmsComposeTask SMSCompose = new SmsComposeTask();
SMSCompose.To = "<Number to which the SMS needs to be sent";
SMSCompose.Body = "Message that needs to be sent";
SMSCompose.Show();
Is there any othey way to achive it?
public async static Task SendMessage (string phoneNumber)
{
ChatMessage msg = new ChatMessage();
msg.MessageKind = Windows.ApplicationModel.Chat.ChatMessageKind.Standard;
msg.Body = "...";
msg.Recipients.Add(phoneNumber);
ChatMessageStore cms = await ChatMessageManager.RequestStoreAsync();
cms.SendMessageAsync(msg);
}
This should send the message on Windows Phone 8.1. You may want to check if cms is not null, just in case...
You should do some searching before make a new thread. Your question is already a part in this thread. The universal app is also called windows runtime, so same solution in that threat if you want to send message or event call or send email.
You can use this for send message:
Windows.ApplicationModel.Chat.ChatMessage msg = new Windows.ApplicationModel.Chat.ChatMessage();
msg.Body = "This is body of demo message.";
msg.Recipients.Add("10086");
msg.Recipients.Add("10010");
await Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(msg);
Enjoy coding!
P/s: update from #Sinaesthetic , this just compose the message, it'll not send it, all user has to do is to hit the send button :)