# C\#

## Setup

To be able to use TextFlow for sending an SMS or user verification, you first have to [register an account](https://textflow.me), after that you are going to get a free API key with two free SMS, which you can use to send SMS or verify user request anywhere in the world.&#x20;

After you have registered an account, your API key will be available on the [API console](https://textflow.me/api).&#x20;

After you have your API key, you need to install the `TextFlow` NuGet package:

```bash
dotnet add package TextFlow
```

Next thing you have to do is just to load the library and supply your API key.&#x20;

```csharp
using TextFlow;

TextFlowClient client = new TextFlowClient("YOUR_API_KEY");
```

## Sending an SMS

Once you have [initialized the library](#setup), you can easily send a simple SMS by using the `SendSMS` function.&#x20;

```csharp
client.SendSMS("+11234567890", "Dummy message text...");
```

You can also handle the result of the function, which contains the information if the message was successfully sent.

```csharp
var res = await client.SendSMS("+11234567890", "Dummy message text...");
if (res.Ok)
    Console.WriteLine(res.Data.Timestamp);
else
    Console.WriteLine(res.Message);
```

`res` is an instance of a class with the following properties:&#x20;

```csharp
public class TextFlowSendMessageResult
{
    public bool Ok { get; } // true if and only if the message was successfully sent
    public int Status { get; }
    public string Message { get; }
    public TextFlowSendMessageData Data { get; }
}
```

While `Data` is an instance of the following class:

```csharp
public class TextFlowSendMessageData
{
    public string To { get; }
    public string Content { get; }
    public string CountryCode { get; }
    public float Price { get; }
    public Int64 Timestamp { get; }
}
```

## User verification

There are two functions that you should call on your back-end during the user verification process, but firstly you should make sure that you have [set up everything correctly](#setup).&#x20;

`SendVerificationSMS` is used to send user the verification code, while the `VerifyCode` is used to check if the code that the user has entered is valid.&#x20;

When you call the `SendVerificationSMS` function, we will send an SMS to the specified phone number. It should be the phone number that you want to verify, e.g. the phone number the user has entered in your app.

After sending the verification SMS, you can show the user a form where he should enter the verification code that he should have got in the SMS. When he submits the code, you should call the `VerifyCode` function and supply his phone number (which he can send again when submitting the code) along with the code that you want verified.

That way, you do not have to worry about keeping data about phone verification in your database, because we are doing it for you.&#x20;

Here is the pseudocode for the whole process:

```csharp
//User has sent his phone number for verification
await client.SendVerificationSMS ("+11234567890", SERVICE_NAME, SECONDS);

//Show him the code submission form

//The user has submitted the code
var result = await client.VerifyCode("+11234567890", "USER_ENTERED_CODE");
//if `result.Valid` is true, then the phone number is verified. 
```

`SERVICE_NAME` is what the user will see in the verification message, e. g. `"Your verification code for Guest is: CODE"`

`SECONDS` is how many seconds the code is valid. Default is 10 minutes. Maximum is one day.

`SendVerificationSMS` is a task that returns the object of the following class:

```csharp
public class TextFlowVerifyPhoneResult
{
    public bool Ok { get; } // true if and only if the code was successfully sent
    public int Status { get; }
    public string Message { get; }
    public TextFlowVerifyPhoneData Data { get; }
}
```

While `TextFlowVerifyPhoneData` has the following properties:

```csharp
public class TextFlowVerifyPhoneData
{
    public string VerificationCode { get; }
    public long Expires { get; }
    public string MessageText { get; }
}
```

And the result of the `VerifyCode` function is an instance of the following class:&#x20;

```csharp
public class TextFlowVerifyCodeResult
{
    public bool Ok { get; }
    public bool Valid { get; } // true if and only if the phone number is verified
    public int Status { get; }
    public string Message { get;  }
    public string? ValidCode { get; }
    public long? Expires { get; }
}
```

## Getting help

If you need help installing or using the library, please check the [FAQ](https://textflow.me/api) first, and contact us at [support@textflow.me](mailto://support@textflow.me) if you don't find an answer to your question.

If you've found a bug in the API, package or would like new features added, you are also free to contact us!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.textflow.me/csharp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
