messagebird / csharp-rest-api Goto Github PK
View Code? Open in Web Editor NEWThis repository contains the open source C# client for MessageBird's REST API.
License: ISC License
This repository contains the open source C# client for MessageBird's REST API.
License: ISC License
i get this error: Could not create SSL/TLS secure channel, why?
Documentation says ViewContact function can take in Name and msidn as optional parameters to view contact. The compiled Nuget Package Code has no input for these optional parameters.
Please help urgently
The client throws an exception when attempting to retrieve a conversation message of type event
. When inspecting the stack trace, this error message appears:
Error converting value "event" to type 'MessageBird.Objects.Conversations.ContentType'. Path 'items[0].type',
On initial inspection, issue seems to be the lack of an Event enum member in MessageBird.Objects.Conversations.ContentType
.
Steps to reproduce
event
with some text content (e.g. when adding a note from a Flow)ListConversationMessages
from SDK client for that conversationExcepted
I'm missing Turkish, for example.
Could you please add the languages that MessageBird has on the web app?
Online you have:
de-DE
en-AU
en-GB
en-US
es-ES
es-MX
es-US
fr-CA
fr-FR
is-IS
it-IT
ja-JP
ko-KR
nl-NL
pl-PL
pt-BR
ro-RO
ru-RU
zh-CN
da-DK
en-IN
cy-GB
nb-NO
pt-PT
sv-SE
tr-TR
el-GR
zh-HK
id-ID
vi-VN
th-TH
ta-IN
ms-MY
In this library I'm missing:
da-DK
en-IN
cy-GB
nb-NO
pt-PT
sv-SE
tr-TR
el-GR
zh-HK
id-ID
vi-VN
th-TH
ta-IN
ms-MY
Thank you!
Hi,
I just query SMS messages:
var messageBird = Client.CreateDefault(AccessKey);
var messages = messageBird.ListMessages(string.Empty, 200);
And I got the following exception in my unit test:
[xUnit.net 00:00:17.17] TestSuite.ApiTests.SmsTests.Should_send_sms_with_template [FAIL]
Failed TestSuite.ApiTests.SmsTests.Should_send_sms_with_template [15 s]
Error Message:
MessageBird.Exceptions.ErrorException : Received response in an unexpected format!
---- Newtonsoft.Json.JsonSerializationException : Error setting value to 'Originator' on 'MessageBird.Objects.Message'.
-------- System.ArgumentException : Originator can only contain numeric or whitespace separated alphanumeric characters.
Stack Trace:
at MessageBird.Resources.Resource.Deserialize(String resource)
at MessageBird.Net.RestClient.RequestWithResource[T](String method, String uri, T resource, HttpStatusCode expectedHttpStatusCode)
at MessageBird.Net.RestClient.Retrieve[T](T resource)
at MessageBird.Client.ListMessages(String status, Int32 limit, Int32 offset)
at TestSuite.ApiTests.SmsTests.Should_send_sms_with_template() in /src/backend/tools/TestSuite/TestSuite.ApiTests/SmsTests.cs:line [133](https://github.com/notifo-io/notifo/runs/6162285497?check_suite_focus=true#step:10:133)
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
at Newtonsoft.Json.JsonSerializer.PopulateInternal(JsonReader reader, Object target)
at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target)
at MessageBird.Resources.Resource.Deserialize(String resource)
----- Inner Stack Trace -----
at MessageBird.Utilities.ParameterValidator.IsValidOriginator(String originator)
at MessageBird.Objects.Message.set_Originator(String value)
at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
[xUnit.net 00:00:28.24] TestSuite.ApiTests.SmsTests.Should_send_sms_without_template [FAIL]
Failed TestSuite.ApiTests.SmsTests.Should_send_sms_without_template [11 s]
Error Message:
MessageBird.Exceptions.ErrorException : Received response in an unexpected format!
---- Newtonsoft.Json.JsonSerializationException : Error setting value to 'Originator' on 'MessageBird.Objects.Message'.
-------- System.ArgumentException : Originator can only contain numeric or whitespace separated alphanumeric characters.
Stack Trace:
at MessageBird.Resources.Resource.Deserialize(String resource)
at MessageBird.Net.RestClient.RequestWithResource[T](String method, String uri, T resource, HttpStatusCode expectedHttpStatusCode)
at MessageBird.Net.RestClient.Retrieve[T](T resource)
at MessageBird.Client.ListMessages(String status, Int32 limit, Int32 offset)
at TestSuite.ApiTests.SmsTests.Should_send_sms_without_template() in /src/backend/tools/TestSuite/TestSuite.ApiTests/SmsTests.cs:line 231
--- End of stack trace from previous location ---
----- Inner Stack Trace -----
at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Populate(JsonReader reader, Object target)
at Newtonsoft.Json.JsonSerializer.PopulateInternal(JsonReader reader, Object target)
at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.PopulateObject(String value, Object target)
at MessageBird.Resources.Resource.Deserialize(String resource)
----- Inner Stack Trace -----
at MessageBird.Utilities.ParameterValidator.IsValidOriginator(String originator)
at MessageBird.Objects.Message.set_Originator(String value)
at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
It just started recently, so I guess I have made a request before (or someone else). It is a shared account between some projects.
But if you store an invalid originator, you also have to return it.
Hi,
I had a look to the API for call flows, but I have no idea how to create a say-step:
https://developers.messagebird.com/api/voice-calling#call-flows
How can I pass additional properties to the step? I think Step and Options should derive from JObject to make this possible.
Shouldn't orgininator be recipient?
File: csharp-rest-api/MessageBird/Objects/Verify.cs
Code: public Verify(string originator, VerifyOptionalArguments arguments = null) { ... }
Hi, I noticed that the list of dependencies on NuGet is not up-to-date with the configuration of the project:
But when I try to use the library there is an error as the library is looking for Json.NET 11.0, it might be interesting to add the dependency to the package definition.
Also, I had a look at the code and it doesn't look like it's mandatory to use the v11 for this project. Would it be possible to push a NuGet version with a more flexible list of dependencies ? My project can only support json.net v10.
Thanks,
This helps with verifying releases and unsigned assemblies cannot be loaded when products are released.
See my PR: #28
I am beginner with this api. How can we send templated message with whatsapp with this api.
Can you please give me a sample code.
There is a bug in the validation of the field Originator.
When a value only exists of numeric characters (so being a phone number) then the value should not be validated on the length. This validation should only be applied on an alphanumeric value.
I noticed this bug because MessageBird sells Virtual Mobile Phone numbers, that can be 13 characters long (e.g: 3197001122334). The validation fails on this, and it shouldn't.
I made a proposal for a fix and added some tests. See PR #16
Please verify. Thanks.
Hello Team,
We are implementing Message Bird API for implementing Two Factor Authentication in C# language. While doing that we were trying to use parameter tokenLength to set the size of token(OTP). But unfortunately its not sending code of given size instead every time it sends 6 Digit code only even though we have requested for 8 digit code.
We are using nuget package version 1.6.0
I'd be happy to help
https://developers.messagebird.com/api/numbers/#fetching-all-purchased-phone-numbers
it's missing from the SDK right?
In testing MessageBird, it doesn't matter what Originator I use in a voice message, it is always delivered with a blocked number (in the US).
How can I get my number to be used when sending voice messages?
The status reports are also not implemented, would be good to get this added too.
https://developers.messagebird.com/docs/sms-messaging#handle-a-status-report
I got this warning when using the nuget package in a .net core v2.0 project
Package 'MessageBird 1.3.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
Eventually this will be a dealbreaker for us.
Hello,
In our project we changed the default JSON.NET configuration to use a enum to string converter globally. Meaning all enums are converted to strings when serialized.
This however causes the messagebird library to stop working, this is due to the Class field in the Message.cs file being an enum, which then is serialized to a string while the underlying messagebird API expects a int.
We currently worked around it by making a fork and changing the Class field to an int, see: Fenetre@2b151fe
But I imagine you would not want to fix it like this and instead use isolated JSON.NET serialization settings instead of the global once.
I am trying to get a list of all calls. I am using the client.ListCalls();
function.
However there's no CallStatus for the status 'no_answer' making the function crashes.
Currently The code i have fetches everything then filters on all results, the payload can be heavy in the future for this.
[HttpGet("{contactId}")]
public List GetConversations(string contactId, [FromHeader(Name = "keys")] string headerKeys)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
MessageBirdKeys mbKeys = serializer.Deserialize(headerKeys);
var restClient = new RestClient(CONVERSATIONS_ENDPOINT, mbKeys.AccessKey, null);
var client = Client.Create(restClient);
ConversationList conversations = client.ListConversations();
return conversations.Items.Where(i => i.ContactId == contactId).ToList();
}
At the moment all API requests in C# clients are executed synchronously. Is there plan to introduce asynchronous methods with async/await and cancellation token support?..
When an image comes from whatsapp , message.content.image property includes caption property, but in sdk, MediaContent class only includes url property. Am i using the wrong class, or is caption property missing ?
Thanks.
If the documentation above is the right documentation for Google Business Messages that can be installed and used via MessageBird, those rich text, how can i set 'containsRichText': 'true',
to be able to use rich text features in GBM ?
Install-Package : Package MessageBird 1.3.4 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package MessageBird 1.3.4 supports: net (.NETFramework,Version=v0.0)
At line:1 char:1
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Install-Package : One or more packages are incompatible with .NETCoreApp,Version=v1.1.
At line:1 char:1
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Install-Package : Package restore failed. Rolling back package changes for 'IsmailiAlliances'.
At line:1 char:1
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
The enum ChannelStatus in MessageBird.Objects.Conversations do not have the options unavailable or not_verified which generate the following errors parsin the JSON:
MessageBird.Exceptions.ErrorException: Received response in an unexpected format! ---> Newtonsoft.Json.JsonSerializationException: Error converting value "unavailable" to type 'MessageBird.Objects.Conversations.ChannelStatus'
MessageBird.Exceptions.ErrorException: Received response in an unexpected format! ---> Newtonsoft.Json.JsonSerializationException: Error converting value "not_verified" to type 'MessageBird.Objects.Conversations.ChannelStatus'.
Using newtonsoft to deserialize a webhook in response to sending a whatsapp message we get the error
Newtonsoft.Json.JsonSerializationException: Error converting value "rejected" to type 'MessageBird.Objects.Conversations.ConversationMessageStatus'. Path 'message.status', line 64, position 24.
---> System.ArgumentException: Requested value 'rejected' was not found.
{
"contact": {
"attributes": {},
"createdDatetime": "2021-01-08T11:06:38Z",
"customDetails": {},
"firstName": "",
"lastName": "",
"updatedDatetime": "2021-01-08T11:06:38Z"
},
"conversation": {
"contactId": "cc7c35b3bbc841438ba5880f3743b06d",
"createdDatetime": "2021-01-08T11:06:38Z",
"id": "f8fece0fc39f46a7a8f9a44ec5b54b9e",
"lastReceivedDatetime": "2021-01-08T11:06:39.17314366Z",
"lastUsedChannelId": "97162e4022fd41dda3cbb4f86a083dc3",
"lastUsedPlatformId": "whatsapp",
"status": "active",
"updatedDatetime": "2021-01-08T11:06:39.189118227Z"
},
"message": {
"content": {
"hsm": {
"language": {
"code": "en",
"policy": "deterministic"
},
"params": [
{
"default": "2 Garden"
},
{
"default": "Saturday, 09/01"
}
],
"templateName": "sendpincode"
}
},
"createdDatetime": "2021-01-08T11:06:39Z",
"direction": "sent",
"error": {
"code": 302,
"description": "The contact is not registered on WhatsApp."
},
"origin": "api",
"platform": "whatsapp",
"status": "rejected",
"type": "hsm",
"updatedDatetime": "2021-01-08T11:06:39Z"
},
"type": "message.updated"
}
It looks like the MessageBird NuGet is not compatible with the lates Windows UWP (see error messages)
Restoring packages for 'IAmOkShared'.
Restoring packages for D:\CloudStation\Visual Studio 2015\IAmOk\IAmOkShared\project.json...
MessageBird 1.3.2 is not compatible with UAP,Version=v10.0.
Some packages are not compatible with UAP,Version=v10.0.
MessageBird 1.3.2 is not compatible with UAP,Version=v10.0 (win10-arm).
Some packages are not compatible with UAP,Version=v10.0 (win10-arm).
MessageBird 1.3.2 is not compatible with UAP,Version=v10.0 (win10-arm-aot).
Some packages are not compatible with UAP,Version=v10.0 (win10-arm-aot).
MessageBird 1.3.2 is not compatible with UAP,Version=v10.0 (win10-x64).
Some packages are not compatible with UAP,Version=v10.0 (win10-x64).
MessageBird 1.3.2 is not compatible with UAP,Version=v10.0 (win10-x64-aot).
Some packages are not compatible with UAP,Version=v10.0 (win10-x64-aot).
MessageBird 1.3.2 is not compatible with UAP,Version=v10.0 (win10-x86).
Some packages are not compatible with UAP,Version=v10.0 (win10-x86).
MessageBird 1.3.2 is not compatible with UAP,Version=v10.0 (win10-x86-aot).
Some packages are not compatible with UAP,Version=v10.0 (win10-x86-aot).
Package restore failed for 'IAmOkShared'.
Package restore failed. Rolling back package changes for 'IAmOkShared'.
Any idea when this is coming?
I am sending a pdf file in whatsapp sandbox, but file is not received. And i got no error or exception while sending.
Is it a bug? Or whatsapp sandbox does not allow sending files?
Sending image and location is working.
In the documentation here https://developers.messagebird.com/api/conversations/#supported-media-types-per-platform
Documentation shows that Google Business Messages support only image media type.
Is there another media types that can be supported ? Is this related to a restriction in Google Business Messages? Or the other possible media types haven't been supported or implemented by MessageBird ?
It would be nice to have async versions of the client methods using HttpClient instead of HttpWebRequest. I don't think I'll have time to try and submit a pull request unfortunately.
There are the functions to:
But there is no function to update.
I would be nice to have this library available in NuGet.
The enum used in the library consists only of two values:
public enum DataEncoding { [EnumMember(Value = "plain")] Plain, [EnumMember(Value = "unicode")] Unicode };
But in the API documentation at https://developers.messagebird.com/docs/messaging a 3rd value is descibed:
The datacoding used, can be plain (GSM 03.38 characters only), unicode (contains non-GSM 03.38 characters) or auto, we will then set unicode or plain depending on the body content.
Can you add the value auto the this enum does a reason exist to not use "auto" from .net / C# side?
During a call with the client to:
messageBirdClient.ListConversationMessages(conversationId);
got error
Error converting value "rejected" to type 'MessageBird.Objects.Conversations.ConversationMessageStatus'. Path 'items[1].status', line 1, position 1187.
Because response contains a message with status = 'rejected', as 'rejected' is missing in public enum ConversationMessageStatus.
Please fix asap!
Please add support for Verify functionality:
https://developers.messagebird.com/docs/verify
https://developers.messagebird.com/api/verifywithemail/#request-a-verify
recipient and originator for now could be set as an email (now string previously were int)
Add support to get status of the verify email message
verify/messages/email
#87
I updated MessageBird nuget package to version 3.0.0
accesskey, channelid and conversationid parameters are from WhatsApp Sandbox page.
When i want to send message, i get error NotFound description: 'Conversation not found' parameter: ''
What can be wrong here ?
Client _client= Client.CreateDefault("accesskey");
ConversationMessageSendRequest _request = new ConversationMessageSendRequest()
{
ChannelId = "channelid",
Type = ContentType.Text,
ConversationId = "conversationid",
Content = new Content() { Text = "hello" }
};
ConversationMessage message = _client.SendConversationMessage(_request.ConversationId, _request);
Any chance of getting an implementation of the verify http request functionality added?
As per: https://developers.messagebird.com/docs/verify-http-requests
Send template example not work
I'm want to add filters to the ListMessages method. To my suprise only the status filter option is available. Now I still need to build my own httpclient implementation...
I am using WhatsApp sandbox.
I implemented request verification from sample code
var requestSigner = new RequestSigner(GetBytes("SIGNING_KEY"));
// @param expectedSignature Signature from the MessageBird-Signature header in its original base64 encoded state.
const string expectedSignature = "EXPECTED_SIGNATURE";
var request = new Request("1544544948", requestParams, GetBytes(requestBody));
requestSigner.IsMatch(expectedSignature, request)
Request verification is working for incoming messages, i have no problem with that. But after i send the response, messagebird api sends a new webhook for delivery status, but request verification is not successfull for that second request.
I am using the same verification code. What can be the issue here ?
Spaces are valid characters in the Originator string, see this MessageBird support page.
However, the regular expression in the Message.Originator setter method only allows the string to contain characters of the alphabet and digits.
Regex | |
---|---|
Current version | ^[A-Za-z0-9]+$ |
Suggested | ^[A-Za-z0-9\s]+$ |
The reportUrl field is missing from SMS, MMS and Voice messages.
See:
https://developers.messagebird.com/docs/sms-messaging#handle-a-status-report
In the RestClient.cs
there is the following code:
csharp-rest-api/MessageBird/Net/RestClient.cs
Lines 203 to 206 in c6e2199
Looking at the source for StreamWriter
in .NET Core latest (should be similar in other runtimes) this only closes but does not dispose the inner stream.
It might be prudent to change the start of the code to:
using (var stream = request.GetRequestStream())
using (var requestWriter = new StreamWriter(stream))
{
requestWriter.Write(body);
}
The specific reason I'm asking for this, is that we're seeing ErrorException
s with inner SocketException
s claiming AddressAlreadyInUse
(10048
) errors. This happens after we send a few thousand SMSs, and seems to indicate that sockets on the host are being consumed faster than they become available. So maybe if we don't wait for the GC to collect the .GetRequestStream()
, and instead dispose via a using
as I suggest, things might improve.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.