Friday, June 10, 2022
HomeWordPress DevelopmentRick Roll Your Pals Utilizing Appwrite, Twilio, and .NET

Rick Roll Your Pals Utilizing Appwrite, Twilio, and .NET


Being the fun-loving man and absolute geek that I’m, I’ve at all times seemed for methods to make use of tech to prank my pals 😏. I keep in mind that first prank I did 11 years again, a bit of shortcut hidden behind an Web Explorer icon that shut down my pal’s Home windows XP primarily based PC and gave him a mini heart-attack 😆. My pranks have gotten “a bit of extra refined” since then, having graduated to rick rolling them by way of telephone calls now! 🤣

Rick Roll GIF

The most effective half is that little prank is very easy to create, and I’ll present you create this prank utilizing 3 of my favorite applied sciences, Appwrite, Twilio, and .NET as we speak! 😄



📃 Desk of Contents



📝 Conditions

Earlier than we get began, there are a few conditions. When you have the conditions arrange already, you possibly can skip to the next part.

So as to comply with alongside, you’ll want a couple of issues beforehand.

  • 🖥 An Appwrite occasion

If you happen to haven’t arrange an Appwrite occasion but, you possibly can comply with the getting began guides to get it up and working shortly. Be happy to decide on between the One-Click on installations on DigitalOcean or [manual installations with Docker].(https://appwrite.io/docs/set up#installWithDocker).

TL;DR: It simply takes a single command to put in Appwrite.

docker run -it --rm 
    --volume /var/run/docker.sock:/var/run/docker.sock 
    --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw 
    --entrypoint="set up" 
    appwrite/appwrite:0.14.2
Enter fullscreen mode

Exit fullscreen mode

As soon as your server is up and working, head over to the Appwrite Dashboard in your server’s public IP deal with ( or localhost when you put in domestically ) and create a brand new admin person account.

Sign Up

So as to allow the .NET 6.0 runtime for Appwrite Cloud Features, you might want to replace the .env file within the Appwrite set up folder. Enter the file and add dotnet-6.0 to the comma-separated record within the atmosphere variable _APP_FUNCTIONS_RUNTIMES. This can make the .NET runtime obtainable in Appwrite Features. You possibly can then load the up to date configuration utilizing the docker-compose up -d command.

  • 🧑‍💻 The Appwrite CLI

We’ll use the Appwrite CLI throughout this train because it makes the method tremendous easy. When you have Node.js put in, the set up command is an easy

npm set up -g appwrite-cli
Enter fullscreen mode

Exit fullscreen mode

If npm is just not your factor, we’ve quite a few set up choices yow will discover within the getting began information for the CLI.

  • 📱 A Twilio Account and Telephone Quantity

Join a Twilio account if you do not have one already. Add a telephone quantity to your account that has calling capabilities on the very minimal.

Twilio Console

ℹ️ The Twilio Account SID and Auth Token may be obtained out of your Twilio console. You should buy a Twilio telephone quantity utilizing this information.



🏗️ Organising Appwrite and Initializing Our Perform

If you happen to already know create a Cloud Perform from the Appwrite CLI, please skip over to the following part.

So as to create an Appwrite Cloud Perform, first we should login to the Appwrite CLI utilizing the appwrite login command utilizing the credentials we created when organising the Appwrite occasion.

appwrite login
? Enter your e-mail take a look at@take a look at.com
? Enter your password ********
? Enter the endpoint of your Appwrite server http://localhost/v1
✓ Success
Enter fullscreen mode

Exit fullscreen mode

Subsequent up, we have to create a brand new Appwrite mission (or hyperlink an present one) to work with. This may be achieved by way of the appwrite init mission command.

appwrite init mission
? How would you want to begin? Create a brand new Appwrite mission
? What would you want to call your mission? Venture X
✓ Success
Enter fullscreen mode

Exit fullscreen mode

You may give your mission any identify you want. As quickly as you create or hyperlink a mission, it’s best to discover a brand new appwrite.json file within the present listing which shops all of the details about your mission.

Now that our CLI is all arrange with our Appwrite mission, let’s initialize our perform utilizing the appwrite init perform command.

appwrite init perform
? What would you want to call your perform? RickRoll
? What runtime would you want to make use of? .NET (dotnet-6.0)
✓ Success 
Enter fullscreen mode

Exit fullscreen mode

Give your perform a reputation (I’ve chosen RickRoll right here for comfort) and select the .NET 6.0 runtime. This can create a brand new Appwrite Perform in your mission and arrange all of the boilerplate code crucial. The perform’s recordsdata can be found within the features/RickRoll listing, which is the place we’ll be working.

If you happen to do not feel comfy creating Appwrite Cloud Features with .NET, please make certain to take a look at our weblog earlier than shifting onto the following step.



🧑‍💻 Creating the Rick Roll Perform

After initializing the RickRoll Perform, please go to the features/RickRoll listing. Our file construction right here appears to be like as follows.

RickRoll
├── Perform.csproj 
|
└── src
    └── Index.cs
Enter fullscreen mode

Exit fullscreen mode

Enter src/Index.cs and substitute the boilerplate with the next code.

utilizing System.Collections.Generic;
utilizing System.Threading.Duties;
utilizing Newtonsoft.Json;
utilizing Twilio;
utilizing Twilio.Varieties;
utilizing Twilio.Relaxation.Api.V2010.Account;

public async Process<RuntimeResponse> Most important(RuntimeRequest req, RuntimeResponse res)
{
  // Convert payload from JSON string to Dictionary and get the telephone quantity to name 
  var payload = JsonConvert.DeserializeObject<Dictionary<string, string>>(req.Payload);
  var toPhoneNumber = payload["phoneNumber"];

  // Get Twilio Account SID, Auth Token, and Telephone Quantity from the Setting Variables
  var accountSID = req.Env["TWILIO_ACCOUNTSID"];
  var authToken = req.Env["TWILIO_AUTHTOKEN"];
  var twilioPhoneNumber = req.Env["TWILIO_PHONENUMBER"];

  //Initialize the Twilio SDK
  TwilioClient.Init(accountSID, authToken);

  // Create the telephone name with the Twilio Voice API
  var name = CallResource.Create(
                to: new PhoneNumber(toPhoneNumber),
                from: new PhoneNumber(twilioPhoneNumber),
                twiml: new Twiml("<Response><Play>https://demo.twilio.com/docs/traditional.mp3</Play></Response>") 
             );

  // Return the response from the Twilio SDK
  return res.Json(new()
  {
    { "twilioResponse", name }
  });
}
Enter fullscreen mode

Exit fullscreen mode

Let’s go over the code we’ve right here. From the Cloud Features documentation, we see that the payload and atmosphere variables can be found via the request object. Right here, we take the payload, which we obtain as a JSON string, and convert it right into a Dictionary. That is achieved utilizing the Newtonsoft.Json library. We seize the telephone quantity we need to name from the deserialized payload as properly.

We then retrieve the Twilio Account SID, Twilio Auth Token, and our Twilio Telephone Quantity from the environment variables and use the Twilio C# / .NET SDK to make a telephone name with a very particular audio 😉.

Dancing to the music

So as to guarantee that Appwrite installs the Newtonsoft.Json library and the Twilio SDK to our perform, we should embody them within the Perform.csproj file.

<ItemGroup>
    <PackageReference Embody="Newtonsoft.Json" Model="13.0.1" />
    <PackageReference Embody="Twilio" Model="5.75.2" />
</ItemGroup>
Enter fullscreen mode

Exit fullscreen mode

Now that our perform is prepared, we will deploy it to our Appwrite occasion utilizing the appwrite deploy perform command.

appwrite deploy perform
? Which features would you prefer to deploy? RickRoll (62a1a474b154de566308)
ℹ Data Deploying perform RickRoll ( 62a1a474b154de566308 )
ℹ Data Ignoring recordsdata utilizing configuration from appwrite.json
✓ Success Deployed RickRoll ( 62a1a474b154de566308 )
Enter fullscreen mode

Exit fullscreen mode

The perform ought to be seen inside your Appwrite Occasion right here.

RickRoll Function

One very last thing we should do earlier than we will take a look at the perform is add the required atmosphere variables to the Perform’s Settings web page.

  • TWILIO_ACCOUNTSID: Twilio Account SID
  • TWILIO_AUTHTOKEN: Twilio Auth Token
  • TWILIO_PHONENUMBER: Twilio Telephone Quantity to make the decision from

RickRoll Environment Variables

Now our perform is totally prepared to check! 🥳



😜 Testing the Rick Roll Cloud Perform

As soon as the perform is deployed, we will head over to the Appwrite console and execute the perform with the payload within the following format.

{
    "phoneNumber": "+919876543210"
}
Enter fullscreen mode

Exit fullscreen mode

RickRoll Payload

Executing the perform ought to result in the telephone quantity you entered receiving a name as proven.


We are able to additionally discover the response from the Twilio SDK within the Perform’s Logs web page.

Function Log



🏆 Conclusion

And that brings us to the top of us! I sincerely hope you loved your self studying how one can leverage Appwrite Cloud Features to construct a enjoyable little prank mission. Be happy to go to the GitHub repo for this mission (and provides it a star 🌟 when you prefer it).

Appwrite Cloud Perform that rick rolls an individual on telephone name by way of Twilio

🤖 Documentation

Appwrite Cloud Perform that rick rolls an individual on telephone name by way of Twilio.

Instance enter:

This perform expects a telephone quantity within the payload within the following format: +[Country Code][Phone Number]

This is an instance JSON enter:

{
    "phoneNumber": "+919876543210"
}
Enter fullscreen mode

Exit fullscreen mode

Instance output:

{
    "twilioResponse": {
        "Sid": "CA83758d533c786be5bcf82e34b94cc8b5"
        "DateCreated": null,
        "DateUpdated": null,
        "ParentCallSid": null,
        "AccountSid": "ACe29c144db149972dbf5427bbdd0c16dd",
        "To": "u002B919876543210",
        "ToFormatted": "u002B919876543210",
        "From": "u002B12184232045",
        "FromFormatted": "(218) 423-2045",
        "PhoneNumberSid": "PN671d012061f32085fcd63b046f23826f",
        "Standing": {},
        "StartTime": null,
        "EndTime": null,
        "Period": null,
        "Value": null,
        "PriceUnit": "USD",
        "Route": "outbound-api"

Enter fullscreen mode

Exit fullscreen mode

In case you need to study extra about Appwrite Cloud Features, be at liberty to go to the Features Information and be at liberty to go to the Appwrite Discord Server when you want any assist.

Thanks so much and hope you will have an excellent day! ❤️

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments