How can I receive the message with custom settings? - connectycube

I created a message template for connectyCube, When I send the message with ConnectyCube.chat.send(recipient_id, msg);
the message is received by the other user but the custom setting is undefined.
My problem is that I want to send the profile picture url and nickname with message to a group.
How can I receive the message with custom settings?

https://developers.connectycube.com/js/messaging?id=sendreceive-chat-messages
Use the extension filed to store any property
const message = {
type: dialog.type === 3 ? 'chat' : 'groupchat',
body: "Hello",
extension: {
dialog_id: dialog.id,
save_to_history: 1,
url1: urlProfile1,
url2: urlProfile2,
some_data: someData
},
markable: 1
};
ConnectyCube.chat.send(recipientIdOrDialogJid, message);

Related

How do I handle Request Body Error in Ktor

I am new to Ktor and I have a route with a request body which i am parsing with Kotlin Serialization.
I know that the request body is expected to conform to the request body data class but then, I tested by passing the wrong field in my test payload and it crashed the app.
I want to be able to handle such scenarios and respond to the client that such a field is not allowed. How do i go about that.
This is my sample data class:
#kotlinx.serialization.Serializable
data class UserLoginDetails(
var email: String = "",
var password: String = ""
)
This is the route:
post("/user/login") {
val userInfo = call.receive<UserLoginDetails>()
//my code here
}
The payload below works
{
"email": "test#email.com",
"password": "password"
}
But if use an alternative payload for instance:
{
"phone": "test#email.com",
"password": "password"
}
The app crashes with the crash message:
kotlinx.serialization.json.internal.JsonDecodingException: Unexpected
JSON token at offset 7: Encountered an unknown key 'emai'. Use
'ignoreUnknownKeys = true' in 'Json {}' builder to ignore unknown
keys.
You have two options in Ktor:
call.receive is the function which can throw an exception in this case, you can simply catch it:
try {
val userInfo = call.receive<UserLoginDetails>()
} catch (t: Throwable) {
// handle error
}
Catching exceptions globally using Status Pages:
install(StatusPages) {
exception<SerializationException> { cause ->
call.respond(/* */)
}
}
The error message says you can setup your Json with the config ignoreUnknownKeys = true where you are creating the Json object. Here's the doc link.
a tip: You might also want to check other configuration options so you can avoid setting empty string as default values.

How to work with messages from WTelegramClient updates? (get chat/user infos)

I'm new to the WTelegramClient C# Library and was used to TLSharp (not working anymore)
I'm trying to understand how I get User info after update is received,
I have the example code that listen to updates and write them in console
but I can't understand how I can respond to the user that sent the message (new update)
I think I need the user id/access_hash to send message to the sender but I can't understand how
Here is how I get the new messages but it can get only username or name/id
private static void DisplayMessage(MessageBase messageBase, bool edit = false)
{
if (edit) Console.Write("(Edit): ");
switch (messageBase)
{
case Message m: Console.WriteLine($"{Peer(m.from_id) ?? m.post_author} in {Peer(m.peer_id)}> {m.message}"); break;
case MessageService ms: Console.WriteLine($"{Peer(ms.from_id)} in {Peer(ms.peer_id)} [{ms.action.GetType().Name[13..]}]"); break;
}
}
Here i can get the name or username of sender(if have) and the message itself
MessageService ('user' not channel or group) for example get me only firstname and lastname
How to get all info of sender or chat itself (i want to try mark as read the message)
I'm used to TLSharp and the new library WTelegramClient is different.
Thanks!!!
Below is a quick example on how to modify DisplayMessage to react to a message sent in private from a user, get the details about this user, verify who it is and which text was sent to us, and then send him a message back.
Notes:
For this example to work, you will need the latest version of Program_ListenUpdates.cs with static variables
DisplayMessage is now async Task, in order to use await
You can pass user to send a message because class User is implicitly converted to InputPeerUser (with the user id/access_hash).
You can do similarly for messages coming from chats, using PeerChat/PeerChannel classes and the _chats dictionary to get chat details
private static async Task DisplayMessage(MessageBase messageBase, bool edit = false)
{
if (edit) Console.Write("(Edit): ");
switch (messageBase)
{
case Message m:
Console.WriteLine($"{Peer(m.from_id) ?? m.post_author} in {Peer(m.peer_id)}> {m.message}");
if (m.flags.HasFlag(Message.Flags.out_))
break; // ignore our own outgoing messages
if (m.Peer is PeerUser pu) // got a message in a direct chat with a user
{
if (_users.TryGetValue(pu.user_id, out var user)) // get user details
{
if (user.username == "Wiz0u" && m.message == "hello")
{
await Client.SendMessageAsync(user, $"hi {user.first_name}, I'm {My.first_name}");
}
}
}
break;
case MessageService ms:
Console.WriteLine($"{Peer(ms.from_id)} in {Peer(ms.peer_id)} [{ms.action.GetType().Name[13..]}]");
break;
}
}

Upload attachment failure Facebook Attachment Upload API

I am trying to add an attachment to my message via facebook attachment upload API.
I am sending from a page (that I am an admin of) to a user that has sent message to my page.
Simple text messages are sent and also attachments as type 'file' is also working correctly. But when I put in 'image' or 'audio' as an attachment, the facebook sends response:
error: {
message: '(#100) Upload attachment failure.',
type: 'OAuthException',
code: 100,
error_subcode: 2018047,
fbtrace_id: 'AzfHWxf3AnikXiCCC-hYJOu'
}
Here is my code:
let messageData = {
message: {
attachment: {
**type: "image"**,
payload: {
is_reusable: true,
url: <url of the image>
}
}
}
}
let data = await axios.post(`https://graph.facebook.com/v8.0/me/message_attachments?access_token=${accessToken}`, messageData)
Upload attachment failure. A common way to trigger this error is that the provided media type does not match type of file provided int the URL
from official docs

How to get data of particular sender and receiver in chatbox?

I want to get all messages history of particular sender and receiver. i am using fronEnd angular5 and Backend Django..
my db sample table :
{
"id": 288,
"name": "Faric",
"receiver": "drit",
"text": "hiee",
"myDate": "2018-07-26T04:38:05.505000Z"
}
chatService:
url : string = 'http://127.0.0.1:8000/msg/';
messages: Subject<ChatMessage>;
getMessage(): Promise<chatMessage[]>{
return this.http.get(this.url).map(res => res.json()).topromise(); #url of messages API
}
chatcomponent:
this.chat.getMessage()
.then(msg=> this.messages = msg); # messges = []
using this service and component i get all mssages.. jst i want to get perticular sender and receiver's data. how to do this?
You can use ES6's find function to fetch data for a particular sender / receiver,
Let's say if you want to get the data based on the ID field (in your json), you can try something like,
this.messageForAnUser = this.messages.find(message=> message.id === THE_SENDER_OR_RECEIVER_ID_YOU_WANT_TO_SEARCH)
Hope this helps!

Hyperlink in content in Amazon Lex

I want to hyperlink a particular text in lambda function content. I tried doing this but didn't work.
if (intentName == "greetings") {
var message = {
'contentType': 'PlainText',
'content': 'click here'
}
responseMsg = close( sessionAttributes, 'Fulfilled', message );
}
I know we can hyperlink response card, but i want to hyperlink a particular text in content. Any idea how to do it or any alternative? i am using javascript.
Edit 1 : I am able to do it by Attachments through attachment :
function close(sessionAttributes,fulfillmentState,message){
return{
sessionAttributes,
dialogAction: {
type: 'Close',
fulfillmentState,
message,
"responseCard": {
"contentType": "application/vnd.amazonaws.card.generic",
"genericAttachments": [
{
'title': 'Google',
'attachmentLinkUrl': 'https://www.google.com',
}
]
}
}
};
}
I was trying this out on HTML a few months ago, you can check out my question at LexResponse output does not understand HTML data
The answer that worked was a JS function that looks like this:
function showResponse(lexResponse) {
var conversationDiv = document.getElementById('conversation');
var responsePara = document.createElement("P");
responsePara.className = 'lexResponse';
if (lexResponse.message) {
var message = lexResponse.message.replace(/"/g, '\'');
responsePara.innerHTML = message;
responsePara.appendChild(document.createElement('br'));
}
conversationDiv.appendChild(responsePara);
conversationDiv.scrollTop = conversationDiv.scrollHeight;
}
Please note that this is only to RENDER the response in HTML.
I implemented this recently.
I wanted a message with custom display, but also wanted normal speech.
Sending text with tags in it will cause the Text to Speech engine to read out the tags as well.
So, for each message I sent to the user, I put the "speechText" into the message content in the Lex response.
I put the "displayText" with tags and what not, within sessionAttributes.
but I had to make sure not to stringify that displayText. I only stringify a value in sessionAttributes if it is not a simple string.
On the client side, I pulled the audio data from the lex response, and I displayed the text I pull from the sessionAttributes.
sry if this is confusing.