Unable to receive correct message in Quickblox - quickblox

When I execute the sample chat program in quickblox, I expect
chatRoom to process the received message: expecting hello from user
Michael Soong. Instead the app shows that the message, it shows a sender
with a number and a body string of the following:
02-24 12:25:22.616: D/RoomChat(27962): sender = 883016
02-24 12:25:22.616: D/RoomChat(27962): body =
{\22message\22\3a\22hello\22,\22name\22\3a\22Michael\20Soong\22,\22avatar\22\3anull,\22fb\22\3anull}

Related

Is .net core accepting only email address from config's MailSettings and only one can be set up?

I am trying to send an email using and getting the following error:
User not local; please try a different path. The server response was:
Sender address is not valid for your login. Check your email program
settings
I have understood that the error appears because in my MailMessage object I am providing another email address for From field than the one set up in the appsettings.json
(.NET was supporting custom sender emails in MailMessage.)
The questions are:
Can I only use the email address in MailMessage.From
field that is provided in appsettings.json's MailSettings?
Can I add more than one email address to appsettings.json's MailSettings?
Is there a way to use a custom MailMessage.From email other than set up in appsettings.json's MailSettings?
MailAddress from = new MailAddress(mailRequest.FromAddress, mailRequest.FromName); // custom "form" that is causing the error
var mailMessage = new MailMessage(from, new MailAddress(mailRequest.ToAddress)) {
Subject = mailRequest.Subject,
Body = mailRequest.Body
};
await _smtpClient.SendMailAsync(mailMessage);
Thanks

How to obtain the chat_id of a private Telegram channel

I use curl to update my public channels. This kind of syntax:
curl -X POST "https://api.telegram.org/bot144377327:AAGqdElkZ-77zsPRoAXXXXXXXXXX/sendMessage" -d "chat_id=#MyChannel&text=my sample text"
But what's the chat_id of a private channel? It's not the one you have in the private invite.
Because now we can pass a channel username (in the format #channelusername) in the place of chat_id in all methods (and instead of from_chat_id in forwardMessage). But what's the #channelusername of a private channel that I administer?
I found the way to write in private channels.
You should convert it to public with some #channelName
Send a message to this channel through the Bot API:
https://api.telegram.org/bot111:222/sendMessage?chat_id=#channelName&text=123
As the response, you will get information with chat_id of your channel.
{
"ok" : true,
"result" : {
"chat" : {
**"id" : -1001005582487,**
"title" : "Test Private Channel",
"type" : "channel"
},
"date" : 1448245538,
"message_id" : 7,
"text" : "123ds"
}
}
Now you can convert the channel back to private (by deleting the channel's link) and send a message directly to the chat_id "-1001005582487":
https://api.telegram.org/bot111:222/sendMessage?chat_id=-1001005582487&text=123
The easiest way:
Just send your invite link to your private channel to #username_to_id_bot (https://t.me/username_to_id_bot) bot. It will return its ID. The simplest level: maximum! :)
PS. I am not an owner of this bot.
PS 2. the Bot will not join your group, but to be sure in security. Just revoke your old invitation link if it is matter for you after bot using.
A more cumbersome way:
Making the channel public cannot be done by the user with exist at least five public groups/channels, so...the problem is not solved. Yes, you can revoke one of them, but for now, we cannot retrieve chat id another way.
Another one working solution:
log in under your account at web version of Telegram: https://web.telegram.org
updated (thanks #Julian Espinel) Find your channel. See to your URL. It should be like https://web.telegram.org/z/#-1543515057
Grab "1543515057" from it, and add "-100" as a prefix.
So... your channel id will be "-1001543515057". Magic happens :)
The solution was found at Web Channel ID .
Open the private channel, then:
on web client:
look at the URL in your browser:
if it's for example https://web.telegram.org/#/im?p=c1192292378_2674311763110923980
then 1192292378 is the channel ID
on mobile and desktop:
copy the link of any message of the channel:
if it's for example https://t.me/c/1192292378/31
then 1192292378 is the channel ID (bonus: 31 is the message ID)
on Plus Messenger for Android:
open the infos of the channel:
the channel ID appears above, right under its name
WARNING be sure to add -100 prefix when using Telegram Bot API:
if the channel ID is for example 1192292378
then you should use -1001192292378
The easiest way is to invite #get_id_bot in your chat and then type:
/my_id #get_id_bot
Inside your chat
Actually, it is pretty simple.
All you need to do is to:
Invite the bot to the channel/group (doesn't matter private or not).
Send any message in the channel/group.
Go to getUpdates API URL in the browser:
https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
Now, look at the results.
You will see a JSON output.
In this JSON, look for the chat data. Usually, latest updates are at the end.
{
"ok":true,
"result":[
...
{
...
"my_chat_member":{
"chat":{
"id":-100987654321,
"title":"My Channel",
"type":"channel"
},
...
}
}
]
}
Your chat ID is -100987654321.
Open Telegram Web at https://web.telegram.org
Search your private channel
Look at the URL. It's like:
https://web.telegram.org/#/im?p=cXXXXXXXXXX_578236787445474833
The id of your private channel is the XXXXXX part (between the "p=c" and the underscore).
To use it, just add "-100" in front of it. So if "XXXXXX" is "4785444554" your private channel id is "-1004785444554".
For now you can write an invite link to bot #username_to_id_bot and you will get the id:
Example:
It also works with public chats, channels and even users.
You can also do this:
Step 1. Convert your private channel to a public channel
Step 2. Set the ChannelName for this channel
Step 3. Then you can change this channel to private
Step 4. Now sending your message using #ChannelName that you set in step 3
Note: For Step 1, you can change one of your public channels to private for a short time.
There isn't any need to convert the channel to public and then make it private.
find the id of your private channel. (There are numerous methods to do this, for example see this Stack Overflow answer.)
curl -X POST "https://api.telegram.org/botxxxxxx:yyyyyyyyyyy/sendMessage" -d
"chat_id=-100CHAT_ID&text=my sample text"
Replace xxxxxx:yyyyyyyyyyy with your bot id, and replace CHAT_ID with the channel id found in step 1. So if the channel id is 1234, it would be chat_id=-1001234.
All done!
Simply and easy; just pass the channel username and it will show you the id:
from telethon.sync import TelegramClient, events
client = TelegramClient("bot", API_ID, API_HASH)
channel_name = "channel username"
channel = client.get_entity(channel_name)
print(f'👉 Channel ID: {channel.id}')
client.start()
client.run_until_disconnected()
The option that I do is by using the popular Plus Messenger on Android.
You can click on the channel and in Channel info below the group name, you can find the channel Id.
Supergroup and channel ids will look like 1068773197 on Plus Messenger. For your usage on API, you can prefix -100 which would make it -1001068773197.
I found the solution for TelegramBotApi for Python. Maybe it will work for other languages.
I just add my bot to the private channel and then do this:
#your_bot_name hi
In the console I get a response with all the information that I need.
I used Telegram.Bot and got the ID the following way:
Add the bot to the channel
Run the bot
Write something into the channel (for example, /authenticate or foo)
Telegram.Bot:
private static async Task Main()
{
var botClient = new TelegramBotClient("key");
botClient.OnUpdate += BotClientOnOnUpdate;
Console.ReadKey();
}
private static async void BotClientOnOnUpdate(object? sender, UpdateEventArgs e)
{
var id = e.Update.ChannelPost.Chat.Id;
await botClient.SendTextMessageAsync(new ChatId(id), $"Hello World! Channel ID is {id}");
}
Plain API:
This translates to the getUpdates method in the plain API, which has an array of update which then contains channel_post.chat.id.
Yet another way to use JavaScript and the Axios library. So you might want to explore /getUpdates method of Telegram API:
const headers: any = {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
timestamp: +new Date(),
}
const options = { headers: { ...headers } }
const urlTelegramBase =
'https://api.telegram.org/bot123456:ABCDEF'
const urlGetUpdates = `${urlTelegramBase}/getUpdates`
const username = 'user_name'
const {
data: { result: messages },
} = await axios.get(urlGetUpdates, options)
const chat_id = messages.find(
messageBlock => messageBlock.message.chat.username === username
).message.chat.id
console.info('chat_id': chat_id)
Run this command in your terminal.
curl https://api.telegram.org/bot{your_bot_token}/getUpdates
But You have added your bot to your private channel.You will get your private channel chat id in json response.
You should add and make your bot an administrator of the private channel. Otherwise, the chat not found error happens.

Bot api, how i can get last message or chat history?

I want implement some functional like user send me a message and I reply to him with my (bot) latest message from chat history.
As you can see in the Telegram Bot API Documentation you can use sendMessage to send a message to the user.
When you receive a message, look for the chat or the from parameter in the JSON (depends if you want to answer to the person when it's a group chat or not). You can use the id parameter of the chat or from to send the message.
So the first parameter for your sendMessage would be chat_id=message.chat.id
You don't need the parse_mode, disable_web_page_preview and reply_markup for this example.
As you want to reply to the message of the user you may want to set the reply_to_message_id to the id of the received message.
reply_to_message_id = message.message_id
Last but not least, you want to set the text parameter. If I understand it correctly, your program will send the last received message.text to the user.
So what you want to do is, as soon as you get a message, save it.
Message oldMessage = message
And when you send the Message to the user use the old messages text property as the text.
text = oldMessage.text
Alright to sum it up here is the pseudocode of the function that will happen as soon as you receive a message:
Message oldMessage = null;
public void NewMessage(Message message){
int chat_id = message.chat.id;
int reply_to_message_id = message.message_id;
String text = "There is no old Message"; //fallback value
if(oldMessage != null){
text = oldMessage.text;
}
//Send Message in this example only has 3 parameters, and ignores the
//not used ones
SendMessage(chat_id,text,reply_to_message_id);
oldMessage = message; //store the received message for future answering
}
As you store the whole message in oldMessage you could also set the text you will send to something like this:
String text = oldMessage.from.first_name+": "+oldMessage.text;
if you simply want to reply on users message you need this function:
public void sendMsg(Message message, String text){
SendMessage sendMessage = new SendMessage();
sendMessage.enableMarkdown(true);
sendMessage.setChatId(message.getChatId().toString());
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setText(text);
try{
setButtons(sendMessage);
sendMessage(sendMessage);
}catch (TelegramApiException e){
e.printStackTrace();
}
}

twilio nuget package not sending SMS message in vb.net

Does the twilio asp.net helper library package NOT work in vb.net? I can get it to work in c# web app but not vb.net web app.
In a vb.net web application project the following code doesnt send an sms message and when stepping through with the debugger, errs on the send message line and brings up a file dialog asking for access to core.cs. The twilio library's were installed via nuget.
Public Shared Sub SendAuthCodeViaSms(ByVal number As String)
Dim twilioAccountInfo As Dictionary(Of String, String) = XmlParse.GetAccountInfoFromXmlFile("twilio")
Dim accountSid As String = twilioAccountInfo("username")
Dim authToken As String = twilioAccountInfo("password")
If (Not String.IsNullOrEmpty(accountSid) AndAlso Not String.IsNullOrEmpty(authToken)) Then
Dim client = New TwilioRestClient(accountSid, authToken)
client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
Else
'log error and alert developer
End If
End Sub
But in a C# web API project the same code sends the message as expected.
protected void Page_Load(object sender, EventArgs e)
{
const string AccountSid = "mysid";
const string AuthToken = "mytoken";
var twilio = new TwilioRestClient(AccountSid, AuthToken);
var message = twilio.SendMessage(TwilioSendNumber,ToNumber,"text message from twilio");
}
and all the sid's and tokens and phone number formats are correct, otherwise the c# one wouldnt send and I wouldnt get to the client.SendMessage part of vb.net version (client.SendSMSMessage produces the same result)
Twilio evangelist here.
I tried our your code by creating a simple VB console app and it worked for me.
The only thing I can think of is that either you are not getting your Twilio credentials correctly when parsing the XML, or the phone number you are passing into the function is not formatted correctly.
I'd suggest putting the result of call to SendMessage() into a variable and checking to see if RestException property is null:
Dim result = client.SendMessage(TwilioSendNumber, ToNumber, "Testmessage from My Twilio number")
If (Not IsNothing(result.RestException)) Then
' Something bad happened
Endif
If Twilio returns a status code greater than 400, then that will show up as an exception in the RestException property and will give you a clue as to whats going on.
If that does not work, you can always break out a tool like Fiddler to watch and see if the library is making the property HTTP request and Twilio is returning the proper result.
Hope that helps.

Can Response UDP Connection?

I Receive Many UDP Connection From None IP Valid Devices With This Code:
receivingUdpClient = New System.Net.Sockets.UdpClient(Port)
Dim byteBuffer As [Byte]() = receivingUdpClient.Receive(RemoteIpEndPoint)
Now I Want Response Data To Device After Receive Data
I use This Code
receivingUdpClient.Send(receiveBytes, 10)
Buy Recived This Error :
"The operation is not allowed on non-connected sockets."
In general, you you need to use SendTo and ReceiveFrom methods instead of Send and Receive with UDP sockets. That way, you can get the IP:port (endpoint) of the sender - so you can send the response back to that same address. My VB is weak, so I'll give you a simple example in C#.
byte [] buffer = new byte[1500];
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
EndPoint senderRemote = (EndPoint)sender;
EndPoint senderRemote;
int bytesReceived = socket.recvFrom(buffer, senderRemote);
// echo the message back to the sender
if (bytesReceived > 0)
socket.sendTo(buffer, bytesReceived, senderRemote);
In your code, RemoteIpEndPoint captures the address you received the data from. To send data back to that host you need to pass that address (endpoint) to your call to Send.