I am building a chat app where Admin creates conversations . The admin email is used as identity to join as participant in the conversation. We add the second participant by its phone number & I have setup the webhooks on twilio number so when the receiver reply on twilio number I intercept the messsage & store in DB and also the messages appear in the conversation.
But when the admin sends the message in conversation using its identity it is received from something secure & not the twilio number. Any suggestions?
I have also set the twilio number in sender pool in twilio messaging service.
async joinConversationByIdentity(conversationSid: string, identity: string) {
const options = {
identity,
};
const conversation = await client.conversations.v1.conversations(conversationSid).participants.create({
...options,
});
return conversation;
}
async joinConversationByPhoneNumber(conversationSid: string, phoneNumber: string) {
const options = {
'messagingBinding.proxyAddress': process.env.TWILIO_PHONE_NUMBER,
'messagingBinding.address': phoneNumber,
};
const conversation = await client.conversations.v1.conversations(conversationSid).participants.create({
...options,
});
return conversation;
}
async sendMessage(author: string, message: string, conversationSid: string) {
const response = await client.conversations.v1.conversations(conversationSid).messages.create({
body: message,
author,
});
const conversation: Conversation = await this.twilioService.getConversationById(conversationSid);
const twilioMessage: TwilioMessage = {
messageSid: response.sid,
accountSid: response.accountSid,
conversationSid: response.conversationSid,
author: response.author,
body: response.body,
participantSid: response.participantSid,
index: response.index,
dateCreated: response.dateCreated,
dateUpdated: response.dateUpdated,
conversation
} as TwilioMessage;
await this.create(twilioMessage);
return response;
}
}
Fahad Mustjab is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.